Results 1 to 3 of 3

Thread: Custom QStyle's methods are not called except for QStyle::polish

  1. #1
    Join Date
    Dec 2009
    Posts
    19
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Custom QStyle's methods are not called except for QStyle::polish

    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:
    Qt Code:
    1. public:
    2. void polish(QPalette &pal);
    3. void polish(QWidget *w);
    4. void unpolish(QWidget *w);
    5.  
    6. int styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData);
    7. int pixelMetric(PixelMetric pm, const QStyleOption *option, const QWidget *widget);
    8.  
    9. void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *w);
    10. void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w);
    11.  
    12. QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *w);
    13.  
    14. public slots:
    15. QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget);
    To copy to clipboard, switch view to plain text mode 
    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)).

  2. #2
    Join Date
    Dec 2009
    Posts
    19
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom QStyle's methods are not called except for QStyle::polish

    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).

  3. #3
    Join Date
    Dec 2008
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom QStyle's methods are not called except for QStyle::polish

    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

    Qt Code:
    1. QIcon standardIconImplementation(QStyle::StandardPixmap standardIcon, const QStyleOption* option = 0,
    2. const QWidget* widget = 0) const;
    To copy to clipboard, switch view to plain text mode 
    but this does:
    Qt Code:
    1. QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption* option = 0,
    2. const QWidget* widget = 0) const;
    To copy to clipboard, switch view to plain text mode 

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.