A paint device in Qt is a drawable 2D surface. QWidget, QPixmap, QPicture and QPrinter are all paint devices.
The default coordinate system of a paint device has its origin located at the top left position. X increases to the right and Y increases downwards. The unit is one pixel.
It is possible to transform the coordinate system when drawing in a paint device.
The illustration below shows a magnified portion of the top left corner of a paint device.
The rectangle and the line were drawn by this code:
void MyWidget::paintEvent( QPaintEvent * ) { QPainter p; p.begin( this ); p.setPen( blue ); p.drawRect( 1,2, 5,4 ); p.setPen( red ); p.drawLine( 9,2, 7,7 ); p.end(); }
The QPainter class has the ability to transform graphics. It can translate, scale, shear and rotate everything from simple lines to text and pixmaps.
The following QPainter functions transform the coordinate system:
In addition, the QPixmap::xForm() function can scale, shear and rotate a pixmap.
Qt has three classes that provide coordinate system support:
All QPainter functions that take point, size or rectangle arguments are overloaded. For example, drawLine() can take the integers (x1,y1,x2,y2) or the QPoints (p1,p2).
Qt does not force you to use QPoint, QSize or QRect. You decide.
Copyright © 1998 Troll Tech | Trademarks | Qt version 1.42
|