This takes a QPainter that has already been set up to paint onto a paint device (either a QWidget or a QGLWidget), a QPaintEvent that provides information about the region to be painted, and a measure of the elapsed time (in milliseconds) since the paint device was last updated. The actual painting is performed in the paint() function. QLinearGradient gradient( QPointF( 50, - 20), QPointF( 80, 20)) ![]() The constructor of the class sets up the resources it needs to paint content onto a widget: Helper ::Helper() Void paint( QPainter *painter, QPaintEvent *event, int elapsed) Īpart from the constructor, it only provides a paint() function to paint using a painter supplied by one of our widget subclasses. The Helper class is minimal: class Helper ![]() We do this because we want the same painting operations to be performed for both our QWidget subclass and the QGLWidget subclass. In this example, the painting operations are performed by a helper class. To do this, we derive subclasses of QWidget and QGLWidget, using a separate Helper class to perform the same painting operations for each, and lay them out in a top-level widget, itself provided a the Window class. To be able to compare the results of painting onto a QGLWidget subclass with native drawing in a QWidget subclass, we want to show both kinds of widget side by side. The QWidget is shown with anti-aliasing enabled, and the QGLWidget will also use anti-aliasing if the required extensions are supported by your system's OpenGL driver. In this example, we perform the same painting operations on a QWidget and a QGLWidget. ![]() The only difference is that the painting operations will be accelerated in hardware if it is supported by your system's OpenGL drivers. Since QGLWidget is a subclass of QWidget, it is possible to reimplement its paintEvent() and use QPainter to draw on the device, just as you would with a QWidget. The QPainter class is used to draw 2D graphics primitives onto paint devices provided by QPaintDevice subclasses, such as QWidget and QImage. The 2D Painting example shows how QPainter and QGLWidget can be used together to display accelerated 2D graphics on supported hardware.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |