Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.
How to use QPainter
Introduction
QPainter provides standard functions to draw points, lines, ellipses, arcs, B’ezier curves, and other primitives. More complex painting operations include support for polygons and vector paths, allowing detailed drawings to be prepared in advance and drawn using a single function call. Text can also be painted directly with a painter or incorporated in a path for later use.
Qt’s painting system also provides a number of features to improve overall rendering quality, including alpha blending, Porter-Duff composition modes, anti-aliasing, and linear, radial and conical gradient fills.
First steps
IMPORTANT! QPainter can paint on QWidget only in
paintEvent(QPaintEvent *)
. Sample code:
This snippet will draw black line on widget. Now we know how to create QPainter object and write on widget. But this isn’t only one of supporting context’s. he can draw on QPrinter, QPicture, QPixmap, QBitmap, QImage, QGLPixelBuffer.
Pen and brush
Pens and brushes are fundamental tools for graphic programming with Qt. Without them, you can’t do anything. So, let’s talk about them.
Pen
Basic usage of pen is drawing circuit lines of shape.