CHAPTER 7Drawing and Printing

All painting in Qt is performed through the QPainter class in one way or another. Widgets, pictures, delegates—everything uses the same mechanism. There is actually one exception to the rule (to use OpenGL directly), but you'll start with the QPainter class.

Drawing Widgets

Using Qt you can draw on almost anything: widgets, pictures, pixmaps, images, printers, OpenGL areas, and so on. The common base class of all these drawables is the QPaintDevice class.

Since a widget is a paint device, you can easily create a QPainter for drawing onto the widget; simply pass this as argument to the constructor, as shown in Listing 7-1.

Listing 7-1. Pass this as argument to the QPainter constructor from a paint event handler ...

Get Foundations of Qt Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.