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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.