A proxy style. More...
#include <qxtproxystyle.h>
Public Member Functions | |
QxtProxyStyle (const QString &baseStyle) | |
virtual | ~QxtProxyStyle () |
virtual void | drawComplexControl (ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget=0) const |
virtual void | drawControl (ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget=0) const |
virtual void | drawItemPixmap (QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const |
virtual void | drawItemText (QPainter *painter, const QRect &rect, int alignment, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole=QPalette::NoRole) const |
virtual void | drawPrimitive (PrimitiveElement elem, const QStyleOption *option, QPainter *painter, const QWidget *widget=0) const |
virtual QPixmap | generatedIconPixmap (QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *option) const |
virtual SubControl | hitTestComplexControl (ComplexControl control, const QStyleOptionComplex *option, const QPoint &pos, const QWidget *widget=0) const |
virtual QRect | itemPixmapRect (const QRect &rect, int alignment, const QPixmap &pixmap) const |
virtual QRect | itemTextRect (const QFontMetrics &metrics, const QRect &rect, int alignment, bool enabled, const QString &text) const |
virtual int | pixelMetric (PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const |
virtual void | polish (QWidget *widget) |
virtual void | polish (QApplication *app) |
virtual void | polish (QPalette &pal) |
virtual QSize | sizeFromContents (ContentsType type, const QStyleOption *option, const QSize &contentsSize, const QWidget *widget=0) const |
virtual QIcon | standardIcon (StandardPixmap standardIcon, const QStyleOption *option=0, const QWidget *widget=0) const |
virtual QPalette | standardPalette () const |
virtual QPixmap | standardPixmap (StandardPixmap standardPixmap, const QStyleOption *option=0, const QWidget *widget=0) const |
virtual int | styleHint (StyleHint hint, const QStyleOption *option=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const |
virtual QRect | subControlRect (ComplexControl control, const QStyleOptionComplex *option, SubControl subControl, const QWidget *widget=0) const |
virtual QRect | subElementRect (SubElement element, const QStyleOption *option, const QWidget *widget=0) const |
virtual void | unpolish (QWidget *widget) |
virtual void | unpolish (QApplication *app) |
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: 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.
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));
Definition at line 31 of file qxtproxystyle.h.
QxtProxyStyle::QxtProxyStyle | ( | const QString & | baseStyle ) | [explicit] |
Constructs a new QxtProxyStyle for style. See QStyleFactory::keys() for supported styles.
Definition at line 88 of file qxtproxystyle.cpp.
: QStyle(), style(QStyleFactory::create(baseStyle))
{
setObjectName(QLatin1String("proxy"));
}
QxtProxyStyle::~QxtProxyStyle | ( | ) | [virtual] |
void QxtProxyStyle::drawComplexControl | ( | ComplexControl | control, |
const QStyleOptionComplex * | option, | ||
QPainter * | painter, | ||
const QWidget * | widget = 0 |
||
) | const [virtual] |
Definition at line 105 of file qxtproxystyle.cpp.
{ style->drawComplexControl(control, option, painter, widget); }
void QxtProxyStyle::drawControl | ( | ControlElement | element, |
const QStyleOption * | option, | ||
QPainter * | painter, | ||
const QWidget * | widget = 0 |
||
) | const [virtual] |
Definition at line 113 of file qxtproxystyle.cpp.
{ style->drawControl(element, option, painter, widget); }
void QxtProxyStyle::drawItemPixmap | ( | QPainter * | painter, |
const QRect & | rect, | ||
int | alignment, | ||
const QPixmap & | pixmap | ||
) | const [virtual] |
Definition at line 121 of file qxtproxystyle.cpp.
{ style->drawItemPixmap(painter, rect, alignment, pixmap); }
void QxtProxyStyle::drawItemText | ( | QPainter * | painter, |
const QRect & | rect, | ||
int | alignment, | ||
const QPalette & | pal, | ||
bool | enabled, | ||
const QString & | text, | ||
QPalette::ColorRole | textRole = QPalette::NoRole |
||
) | const [virtual] |
Definition at line 129 of file qxtproxystyle.cpp.
{ style->drawItemText(painter, rect, alignment, pal, enabled, text, textRole); }
void QxtProxyStyle::drawPrimitive | ( | PrimitiveElement | elem, |
const QStyleOption * | option, | ||
QPainter * | painter, | ||
const QWidget * | widget = 0 |
||
) | const [virtual] |
Definition at line 137 of file qxtproxystyle.cpp.
{ style->drawPrimitive(elem, option, painter, widget); }
QPixmap QxtProxyStyle::generatedIconPixmap | ( | QIcon::Mode | iconMode, |
const QPixmap & | pixmap, | ||
const QStyleOption * | option | ||
) | const [virtual] |
Definition at line 145 of file qxtproxystyle.cpp.
{
return style->generatedIconPixmap(iconMode, pixmap, option);
}
QStyle::SubControl QxtProxyStyle::hitTestComplexControl | ( | ComplexControl | control, |
const QStyleOptionComplex * | option, | ||
const QPoint & | pos, | ||
const QWidget * | widget = 0 |
||
) | const [virtual] |
Definition at line 153 of file qxtproxystyle.cpp.
{
return style->hitTestComplexControl(control, option, pos, widget);
}
QRect QxtProxyStyle::itemPixmapRect | ( | const QRect & | rect, |
int | alignment, | ||
const QPixmap & | pixmap | ||
) | const [virtual] |
Definition at line 161 of file qxtproxystyle.cpp.
{
return style->itemPixmapRect(rect, alignment, pixmap);
}
QRect QxtProxyStyle::itemTextRect | ( | const QFontMetrics & | metrics, |
const QRect & | rect, | ||
int | alignment, | ||
bool | enabled, | ||
const QString & | text | ||
) | const [virtual] |
Definition at line 169 of file qxtproxystyle.cpp.
{
return style->itemTextRect(metrics, rect, alignment, enabled, text);
}
int QxtProxyStyle::pixelMetric | ( | PixelMetric | metric, |
const QStyleOption * | option = 0 , |
||
const QWidget * | widget = 0 |
||
) | const [virtual] |
Definition at line 177 of file qxtproxystyle.cpp.
{
return style->pixelMetric(metric, option, widget);
}
void QxtProxyStyle::polish | ( | QWidget * | widget ) | [virtual] |
Definition at line 185 of file qxtproxystyle.cpp.
{ style->polish(widget); }
void QxtProxyStyle::polish | ( | QApplication * | app ) | [virtual] |
Definition at line 193 of file qxtproxystyle.cpp.
{ style->polish(app); }
void QxtProxyStyle::polish | ( | QPalette & | pal ) | [virtual] |
Definition at line 201 of file qxtproxystyle.cpp.
{ style->polish(pal); }
QSize QxtProxyStyle::sizeFromContents | ( | ContentsType | type, |
const QStyleOption * | option, | ||
const QSize & | contentsSize, | ||
const QWidget * | widget = 0 |
||
) | const [virtual] |
Definition at line 209 of file qxtproxystyle.cpp.
{
return style->sizeFromContents(type, option, contentsSize, widget);
}
QIcon QxtProxyStyle::standardIcon | ( | StandardPixmap | standardIcon, |
const QStyleOption * | option = 0 , |
||
const QWidget * | widget = 0 |
||
) | const [virtual] |
Definition at line 217 of file qxtproxystyle.cpp.
{ return style->standardIcon(standardIcon, option, widget); }
QPalette QxtProxyStyle::standardPalette | ( | ) | const [virtual] |
Definition at line 225 of file qxtproxystyle.cpp.
{
return style->standardPalette();
}
QPixmap QxtProxyStyle::standardPixmap | ( | StandardPixmap | standardPixmap, |
const QStyleOption * | option = 0 , |
||
const QWidget * | widget = 0 |
||
) | const [virtual] |
Definition at line 233 of file qxtproxystyle.cpp.
{ return style->standardPixmap(standardPixmap, option, widget); }
int QxtProxyStyle::styleHint | ( | StyleHint | hint, |
const QStyleOption * | option = 0 , |
||
const QWidget * | widget = 0 , |
||
QStyleHintReturn * | returnData = 0 |
||
) | const [virtual] |
Definition at line 241 of file qxtproxystyle.cpp.
{
return style->styleHint(hint, option, widget, returnData);
}
QRect QxtProxyStyle::subControlRect | ( | ComplexControl | control, |
const QStyleOptionComplex * | option, | ||
SubControl | subControl, | ||
const QWidget * | widget = 0 |
||
) | const [virtual] |
Definition at line 249 of file qxtproxystyle.cpp.
{
return style->subControlRect(control, option, subControl, widget);
}
QRect QxtProxyStyle::subElementRect | ( | SubElement | element, |
const QStyleOption * | option, | ||
const QWidget * | widget = 0 |
||
) | const [virtual] |
Definition at line 257 of file qxtproxystyle.cpp.
{
return style->subElementRect(element, option, widget);
}
void QxtProxyStyle::unpolish | ( | QApplication * | app ) | [virtual] |
Definition at line 273 of file qxtproxystyle.cpp.
{ style->unpolish(app); }
void QxtProxyStyle::unpolish | ( | QWidget * | widget ) | [virtual] |
Definition at line 265 of file qxtproxystyle.cpp.
{ style->unpolish(widget); }