Styles Example
Files:
widgets/styles/norwegianwoodstyle.cpp
widgets/styles/norwegianwoodstyle.h
widgets/styles/widgetgallery.cpp
widgets/styles/widgetgallery.h
widgets/styles/main.cpp
widgets/styles/styles.pro
widgets/styles/styles.qrc
Images:
widgets/styles/images/woodbackground.png
widgets/styles/images/woodbutton.png
The Styles example illustrates how to create custom widget drawing styles using Qt, and demonstrates Qt's predefined styles.
A style in Qt is a subclass of QStyle or of one of its subclasses. Styles perform drawing on behalf of widgets. Qt provides a whole range of predefined styles, either built into the QtGui library or found in plugins. Custom styles are usually created by subclassing one of Qt's existing style and reimplementing a few virtual functions.
In this example, the custom style is called NorwegianWoodStyle and derives from QMotifStyle. Its main features are the wooden textures used for filling most of the widgets and its round buttons and comboboxes.
To implement the style, we use some advanced features provided by QPainter, such as antialiasing (to obtain smoother button edges), alpha blending (to make the buttons appeared raised or sunken), and painter paths (to fill the buttons and draw the outline). We also use many features of QBrush and QPalette.
The example consists of the following classes:
NorwegianWoodStyle inherits from QMotifStyle and implements the Norwegian Wood style.
WidgetGallery is a QDialog subclass that shows the most common widgets and allows the user to switch style dynamically.
Files:
widgets/styles/norwegianwoodstyle.cpp
widgets/styles/norwegianwoodstyle.h
widgets/styles/widgetgallery.cpp
widgets/styles/widgetgallery.h
widgets/styles/main.cpp
widgets/styles/styles.pro
widgets/styles/styles.qrc
Images:
widgets/styles/images/woodbackground.png
widgets/styles/images/woodbutton.png
The Styles example illustrates how to create custom widget drawing styles using Qt, and demonstrates Qt's predefined styles.
A style in Qt is a subclass of QStyle or of one of its subclasses. Styles perform drawing on behalf of widgets. Qt provides a whole range of predefined styles, either built into the QtGui library or found in plugins. Custom styles are usually created by subclassing one of Qt's existing style and reimplementing a few virtual functions.
In this example, the custom style is called NorwegianWoodStyle and derives from QMotifStyle. Its main features are the wooden textures used for filling most of the widgets and its round buttons and comboboxes.
To implement the style, we use some advanced features provided by QPainter, such as antialiasing (to obtain smoother button edges), alpha blending (to make the buttons appeared raised or sunken), and painter paths (to fill the buttons and draw the outline). We also use many features of QBrush and QPalette.
The example consists of the following classes:
NorwegianWoodStyle inherits from QMotifStyle and implements the Norwegian Wood style.
WidgetGallery is a QDialog subclass that shows the most common widgets and allows the user to switch style dynamically.