Qt-UI

QPainter

Using SVN | | Event Loop

QPainter is an imperative style drawing backend.

QPainter Class Reference

Method excerpt:

  • drawEllipse, drawLine, drawPoint, drawPolygon, drawPolyLine, drawRect (fillRect)
  • drawPixmap, drawImage, drawPicture
  • drawText
    • setFont
  • setWorldTransform - see also Qt Coordinate Systems
    • rotate, scale, translate
  • setOpacity(float), setPen(QColor), setBrush(QBrush)
    • setCompositionMode

Geometric vector and attribute specificiations are done via QPoint, QLine, QRect and QColor classes. Some examples:

QPoint(10,10) QPointF(1.5,9.5)
QRect(0,0,width()-1,height()-1)
QColor(r,g,b,a) QColor("red")

The QPixmap class is an off-screen image representation that can be used as a paint device.

QPixmap pix(100,100);
QPainter p(&pix);
p.drawEllipse(50,50,10,10);

The QImage class is an image representation with pixel (QColor) accessors for and IO access. It can dierctly load JPEG or PNG image files (and a few more picture formats).

QImage img;
img.load("image.png");

A QPicture is a recording of QPainter drawing commands. When drawing a QPicture the recorded QPainter commands are replayed. A QPicture is device independent, serializable and storage-efficient.

// record
QPicture pic(100,100);
QPainter p;
p.begin(&pic);
p.drawEllipse(50,50,10,10);
p.end();

// replay
p.begin(&img);
p.drawPicture(0,0,picture);
p.end();

As opposed to QPainter’s imperative style, Qt 5.0 supports a retained mode style with the introduction of the Qt Scene Graph for descriptive definition of drawings. It is utilizing OpenGL ES on the backend side.

Using SVN | | Event Loop

Options: