QFont underline is a property of a QFont object in C++ which when enabled, renders the text with an underline. The underline style and color can also be customized using QFontMetrics and QPen classes respectively. This property can be set and retrieved using the underline() and setUnderline() functions respectively.
Example 1: To enable underline for a QFont object.
QFont font("Times New Roman", 12); // Create a QFont object font.setUnderline(true); // Enable underline property
Example 2: To customize the underline style and color of a QFont object.
QFont font("Times New Roman", 12); // Create a QFont object font.setUnderline(true); // Enable underline property QFontMetrics metrics(font); // Create a QFontMetrics object to get underline height QPen pen(Qt::red); // Create a QPen object with red color pen.setWidth(3); // Set underline width painter.setFont(font); // Set font for the painter painter.setPen(pen); // Set pen for the painter painter.drawLine(QPoint(x, y + metrics.descent()), // Draw the underline QPoint(x + metrics.width(str), y + metrics.descent()));
The package library for QFont and its related classes is Qt, which is a cross-platform toolkit for GUI application development in C++.
C++ (Cpp) QFont::underline - 30 examples found. These are the top rated real world C++ (Cpp) examples of QFont::underline extracted from open source projects. You can rate examples to help us improve the quality of examples.