QFont font("Arial", 20, QFont::Bold); QPainter painter(widget); painter.setFont(font); painter.drawText(10, 10, "Hello World!");
QFont font("Times New Roman", 14); QPainter painter(widget); painter.setFont(font); painter.setPen(Qt::red); painter.drawText(10, 10, "Qt is amazing!");Here, we set the font to Times New Roman with a font size of 14 using setFont. Then we use the setPen method to set the color of the font to red. Finally, we use the painter to draw the text with the selected font and color. Package Library: Qt.