There's more…

The QPainter class uses the coordinate system to determine the position and size of the graphics before rendering them onscreen. This information can be altered to make the graphics appear at a different position, rotation, and size. This process of altering the coordinate information of a graphic is what we called coordinate transformation. There are several types of transformation; among them are translation, rotation, scaling, and shearing:

Qt uses a coordinate system that has its origin at the top-left corner, meaning the x values increase to the right and the y values increase downward. This coordinate system might be different from the coordinate system used by the physical device, such as a computer screen. Qt handles this automatically by using the QPaintDevice class, which maps Qt's logical coordinates to the physical coordinates.

QPainter provides four transform operations to perform different types of transformation:

  • QPainter::translate(): Offsets the graphic's position by a given set of units
  • QPainter::rotate(): Rotates the graphics around the origin in a clockwise direction
  • QPainter::scale(): Offsets the graphic's size by a given factor
  • QPainter::shear(): Twists the graphic's coordinate system around the origin