Qt Basic Drawing
Objectives
- Learn how to draw on widgets
- Understand the difference between QPixmap, QImage and QPicture
- Be able to load an image from a file
QPainter
- QPainter can draw geometric shapes (points, lines, rectangles, ellipses, arcs, chords, pie segments, polygons, and Bézier curves) and also pixmaps, images, and text.
- QPainter can be used to draw on a "paint device", like a QWidget, a QPixmap or a QImage.
- The way the drawing is performed is influenced by QPainter's settings. The three main settings are:
- Pen: Used for drawing lines and shape outlines.
- Brush: Pattern used for filling geometric shapes.
- Font: For drawing text.
- These settings can be modified by calling setPen(), setBrush(), and setFont() with a QPen, QBrush, or QFont object.
Difference between QPixmap, QImage and QPicture
- Qt provides four classes for handling image data: QImage, QPixmap and QPicture.
- QImage provides a hardware-independent image representation. It is is designed and optimized for I/O, and for direct pixel access and manipulation
- QPixmap is designed and optimized for showing images on screen.
- QPicture class is a paint device that records and replays QPainter commands.