![]() |
Home · All Classes · alphabetical Classes List · Modules · Functions · |
A technique called "proxy style" is a common way for creating cross-platform custom styles. Developers often want to do slight adjustments in some specific values returned by QStyle. A proxy style is the solution to avoid subclassing any platform specific style (eg. QPlastiqueStyle, QWindowsXPStyle, or QMacStyle) and to retain the native look on all supported platforms.
The subject has been discussed in Qt Quarterly 9: http://doc.trolltech.com/qq/qq09-q-and-a.html#style (just notice that there are a few noteworthy spelling mistakes in the article).
Proxy styles are becoming obsolete thanks to style sheets introduced in Qt 4.2. However, style sheets still is a new concept and only a portion of features are supported yet. Both - style sheets and proxy styles - have their pros and cons.
class MyCustomStyle : public QxtProxyStyle { public: MyCustomStyle(const QString& baseStyle) : QxtProxyStyle(baseStyle) { } int pixelMetric(PixelMetric metric, const QStyleOption* option = 0, const QWidget* widget = 0) const { if (metric == QStyle::PM_ButtonMargin) return 6; return QxtProxyStyle::pixelMetric(metric, option, widget); } };
Using the custom style for the whole application:
QString defaultStyle = QApplication::style()->objectName();
QApplication::setStyle(new MyCustomStyle(defaultStyle));
Using the custom style for a single widget:
QWidget* widget = ...;
QString defaultStyle = widget->style()->objectName();
widget->setStyle(new MyCustomStyle(defaultStyle));
Constructs a new QxtProxyStyle for style. See QStyleFactory for supported styles.
Destructs the proxy style.
(c) 2007A.Picciani and A.Higerd LGPL | libqxt 0.2 |