O'Reilly logo

Foundations of Qt Development by Johan Thelin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required