QStyle example

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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值