Drawing text

Additionally, you can also draw text using the QPainterclass. All you need to do is to call QPainter::setFont() to set the font properties before calling QPainter::drawText(), like so:

QPainter painter; 
painter.begin(this); 
 
// Draw Text 
painter.setFont(QFont("Times", 14, QFont::Bold)); 
painter.drawText(QPoint(20, 30), "Testing"); 
 
// Draw Line 
painter.drawLine(QPoint(50, 60), QPoint(100, 100)) 

The setFont() function is optional as you will get a default font if you don't specify it. Once you're done, build and run the program. You should see the word Hello World! displayed in the window:

As you can see here, the vector shapes are basically generated by Qt in real time, which looks perfectly fine regardless of how you rescale the window and change its aspect ratio. If you're rendering a bitmap image instead, its visual quality may get degraded when its rescaled along with the window or changed in its aspect ratio.