Results 1 to 4 of 4

Thread: palette setColor QPushButton

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default palette setColor QPushButton

    I'm sorry about this, I know there are lots of threads changing the colours of widgets, but it's just not working for my QPushButton.

    I do this first
    Qt Code:
    1. buttonH1->setAutoFillBackground (true);
    To copy to clipboard, switch view to plain text mode 
    and then I've tried this
    Qt Code:
    1. buttonH1->setPalette(Qt::green);
    To copy to clipboard, switch view to plain text mode 
    and this
    Qt Code:
    1. QPalette palette;
    2. palette.setColor(QPalette::Button, Qt::green);
    3. buttonH1->setPalette(palette);
    To copy to clipboard, switch view to plain text mode 
    and this
    Qt Code:
    1. palette.setColor(buttonH1->backgroundRole(), Qt::green);
    2. buttonH1->setPalette(palette);
    To copy to clipboard, switch view to plain text mode 
    I get a green 'lining' around the button and/or green text but the button itself remains grey.

    I've also tried setting all the palette to green, as below. I don't get a green button.
    Qt Code:
    1. //palette.setColor(QPalette::Window, Qt::green);
    2. //palette.setColor(QPalette::Background, Qt::green);
    3. //palette.setColor(QPalette::WindowText, Qt::green);
    4. //palette.setColor(QPalette::Foreground, Qt::green);
    5. //palette.setColor(QPalette::Base, Qt::green);
    6. //palette.setColor(QPalette::AlternateBase, Qt::green);
    7. //palette.setColor(QPalette::Text, Qt::green);
    8. palette.setColor(QPalette::Button, Qt::green);
    9. //palette.setColor(QPalette::ButtonText, Qt::green);
    10. //palette.setColor(QPalette::BrightText, Qt::green);
    To copy to clipboard, switch view to plain text mode 

    Could somebody please tell me what I need to do?
    thanks
    K

  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: palette setColor QPushButton

    Are you using WinXP? It's not possible with QWindowsXPStyle (it uses native WinXP theming engine for drawing controls such buttons). You could try to set the style of the button explicitly to something else like:

    Qt Code:
    1. QStyle* style = new QPlastiqueStyle; // or QWindowsStyle
    2. buttonH1->setStyle(style);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

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

    TheKedge (2nd November 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: palette setColor QPushButton

    brilliant, thanks! What other widgets are affected by that? Is there a list anywhere? Documentation?

    thanks,
    K

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: palette setColor QPushButton

    Furthermore, if you are using Qt4.2, you can achieve the same quickly by setting a stylesheet for your button. The stylesheet string should contain something like: "background: green;"

    Quote Originally Posted by TheKedge View Post
    brilliant, thanks! What other widgets are affected by that? Is there a list anywhere? Documentation?
    WindowsXP style and Mac Aqua styles are affected in general.That's the famous "red pushbutton issue". That's why Trolltech introduced stylesheets for their widgets in Qt 4.2. I suggest you take a look at its documentation (http://doc.trolltech.com/4.2/stylesheets.html).

Similar Threads

  1. How to reset the Palette for form
    By donmorr in forum Qt Tools
    Replies: 3
    Last Post: 12th August 2006, 12:14
  2. Palette definition
    By Roberto Sciascia in forum Qt Tools
    Replies: 3
    Last Post: 21st March 2006, 15:29
  3. fixing my widget's palette
    By alanh in forum Qt Programming
    Replies: 2
    Last Post: 28th February 2006, 16:10

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
  •  
Qt is a trademark of The Qt Company.