StylingQt's built-in widgets use the QStyle class to perform nearly all of their drawing. QStyle is an abstract base class that encapsulates the look and feel of a GUI, and can be used to make the widgets look exactly like the equivalent native widgets or to give the widgets a custom look. Qt provides a set of QStyle subclasses that emulate the native look of the different platforms supported by Qt (QWindowsStyle, QMacStyle, QMotifStyle, etc.). These styles are built into the QtGui library, other styles can be made available using Qt's plugin mechansim. Most functions for drawing style elements take four arguments:
The style gets all the information it needs to render the graphical element from the QStyleOption class. The widget is passed as the last argument in case the style needs it to perform special effects (such as animated default buttons on Mac OS X), but it isn't mandatory. In fact, QStyle can be used to draw on any paint device (not just widgets), in which case the widget argument is a zero pointer. The paint system also provides the QStylePainter class inheriting from QPainter. QStylePainter is a convenience class for drawing QStyle elements inside a widget, and extends QPainter with a set of high-level drawing functions implemented on top of QStyle's API. The advantage of using QStylePainter is that the parameter lists get considerably shorter.
For more information about widget styling and appearance, see the Styles and Style Aware Widgets. [Previous: Reading and Writing Image Files] [Next: Printing with Qt] © 2008-2011 Nokia Corporation and/or its subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. Privacy Policy Licensees holding valid Qt Commercial licenses may use this document in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Nokia. Alternatively, this document may be used under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. |