QPainter is a Qt class that provides low-level painting on widgets or other paint devices.
QPainter
provides optimized drawing functions that can draw lines, simple shapes, pixmaps, etc. QPainter
can be used with any class that inherits QPaintDevice
class.
A common use of QPainter is drawing inside a widget's paintEvent()
. A simple example of usage will look like this:
void someWidget::paintEvent(QPaintEvent *)
{
//creating a painter
QPainter painter(this);
//setting the pen color
painter.setPen(Qt::red);
//setting the font attributes
painter.setFont(QFont("Arial", 30));
//rendering text.
painter.drawText(rect(), Qt::AlignCenter, "Qt");
}
QPainter
is highly customizable which allows a great variety in drawing capabilities.
Official documentation of this class can be found here for Qt 4.8 and here for Qt 5.