![]() |
Home · Modules · Classes · Namespaces · Functions |
The QxtProxyStyle class provides a proxy style. More...
#include <QxtProxyStyle>
Inherits QStyle.
The QxtProxyStyle class provides a proxy style.
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 (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.
Implement the custom behaviour in a subclass of QxtProxyStyle:
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:
QString defaultStyle = widget->style()->objectName(); widget->setStyle(new MyCustomStyle(defaultStyle));
Constructs a new QxtProxyStyle for baseStyle. See QStyleFactory::keys() for supported styles.
See also QStyleFactory::keys().
Destructs the proxy style.
Copyright © 2007-2011 Qxt Foundation |
Qxt 0.6.2 |