PDA

View Full Version : Custom QStyle's methods are not called except for QStyle::polish



nateriver
25th December 2009, 12:00
Hello,
I'm developing a custom style and have a little problem. I've created a class (let's call it RStyle) inherited from QWindowsStyle with the following methods implemented:


public:
void polish(QPalette &pal);
void polish(QWidget *w);
void unpolish(QWidget *w);

int styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData);
int pixelMetric(PixelMetric pm, const QStyleOption *option, const QWidget *widget);

void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *w);
void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w);

QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *w);

public slots:
QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget);
I also added some tracing in the begging of each method (output to stdout). Tracing showed that only polish (both overloaded methods) is called when creating a widget, other methods are not called (so only widget's palette is altered according to the style).
Any ideas why?

Custom style is set with QApplication::setStyle(new RStyle()) after the QApplication object is constructed.
RStyle itself is declared and implemented in dynamic library.

P.S. I'm using Qt 4.6 (2009.05), QtCreator 1.3, Windows XP SP3 (with Classic theme (Win98-style)).

nateriver
26th December 2009, 10:12
The problem is solved; apparently 'const' qualifier is included in method signature thus can be used to overload methods and must be specified to override method (if the same method in parent class has it). :o

kakkaroolari
14th July 2011, 13:28
I also encountered a similar problem, but the solution was a slightly different scope specifier in one of the arguments. I discovered that, this doesn't work


QIcon standardIconImplementation(QStyle::StandardPixmap standardIcon, const QStyleOption* option = 0,
const QWidget* widget = 0) const;
but this does:

QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption* option = 0,
const QWidget* widget = 0) const;