Results 1 to 8 of 8

Thread: Styling QDockWidget's titlebar buttons

  1. #1
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Styling QDockWidget's titlebar buttons

    Hi everybody!

    I need to change images of title bar buttons of a QDockWidget. The docs say that it can be done with custom QStyle.

    Could anyone give me a hint ?
    C++ & AMD forever

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Styling QDockWidget's titlebar buttons

    Get yourself a [WIKI]proxy style[/WIKI], reimplement QStyle::standardIcon() and return something fancy for QStyle::SP_TitleBarNormalButton and QStyle::SP_TitleBarCloseButton.
    J-P Nurmi

  3. #3
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Styling QDockWidget's titlebar buttons

    Thanks I'll try that
    C++ & AMD forever

  4. #4
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Styling QDockWidget's titlebar buttons

    I've tried to follow your advice but it doesn't work
    Qt Code:
    1. class MyStyle : public ProxyStyle
    2. {
    3. public:
    4. MyStyle(const QString &baseStyle);
    5.  
    6. int pixelMetric(PixelMetric metric, const QStyleOption* option = 0,
    7. const QWidget* widget = 0) const;
    8.  
    9. QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption* option = 0,
    10. const QWidget* widget = 0) const;
    11. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. int MyStyle::pixelMetric(PixelMetric metric, const QStyleOption* option,
    2. const QWidget* widget) const
    3. {
    4. if (metric == PM_DockWidgetHandleExtent || metric == PM_DockWidgetSeparatorExtent)
    5. {
    6. qDebug()<<"PM_DockWidgetHandleExtent";
    7. return 110;
    8. }
    9. else
    10. return ProxyStyle::pixelMetric(metric, option, widget);
    11. }
    12.  
    13. QIcon MyStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption* option,
    14. const QWidget* widget) const
    15. {
    16. if(standardIcon == SP_TitleBarNormalButton)
    17. return QIcon(QPixmap(":/resources/backfordropdown.jpg"));
    18. else
    19. return ProxyStyle::standardIcon(standardIcon, option, widget);
    20. }
    To copy to clipboard, switch view to plain text mode 
    C++ & AMD forever

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Styling QDockWidget's titlebar buttons

    Sorry for misleading, but as QStyle::standardIcon() says:
    Warning: Because of binary compatibility constraints, this function is not virtual. If you want to provide your own icons in a QStyle subclass, reimplement the standardIconImplementation() slot in your subclass instead. The standardIcon() function will dynamically detect the slot and call it.
    So, switch to QStyle::standardIconImplementation()...
    J-P Nurmi

  6. #6
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Styling QDockWidget's titlebar buttons

    It doesn't work that way either
    Qt Code:
    1. class MyStyle : public ProxyStyle
    2. {
    3. public:
    4. MyStyle(const QString &baseStyle);
    5.  
    6. int pixelMetric(PixelMetric metric, const QStyleOption* option = 0,
    7. const QWidget* widget = 0) const;
    8.  
    9. public slots:
    10. QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption* option = 0,
    11. const QWidget* widget = 0) const;
    12. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. int MyStyle::pixelMetric(PixelMetric metric, const QStyleOption* option,
    2. const QWidget* widget) const
    3. {
    4. if (metric == PM_DockWidgetHandleExtent || metric == PM_DockWidgetSeparatorExtent)
    5. {
    6. qDebug()<<"PM_DockWidgetHandleExtent";
    7. return 110;
    8. }
    9. else
    10. return ProxyStyle::pixelMetric(metric, option, widget);
    11. }
    12.  
    13. QIcon MyStyle::standardIconImplementation(StandardPixmap standardIcon, const QStyleOption* option,
    14. const QWidget* widget) const
    15. {
    16. if(standardIcon == SP_TitleBarNormalButton)
    17. return QIcon(QPixmap(":/resources/backfordropdown.jpg"));
    18. else
    19. return ProxyStyle::standardIcon(standardIcon, option, widget);
    20. }
    To copy to clipboard, switch view to plain text mode 
    pixelMetric also doesn't work
    C++ & AMD forever

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Styling QDockWidget's titlebar buttons

    Your MyStyle class is missing the required Q_OBJECT macro. Make sure to re-run qmake after adding it.
    J-P Nurmi

  8. The following user says thank you to jpn for this useful post:

    THRESHE (16th July 2008)

  9. #8
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Styling QDockWidget's titlebar buttons

    Thanks now it works
    C++ & AMD forever

Similar Threads

  1. QSkinWindows Classes
    By kernel_panic in forum Qt-based Software
    Replies: 45
    Last Post: 20th April 2010, 12:35
  2. Replies: 9
    Last Post: 9th May 2006, 19:53

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.