Results 1 to 4 of 4

Thread: Change background color of QPushButton

  1. #1
    Join Date
    Jan 2006
    Posts
    29
    Qt products
    Qt4
    Platforms
    Windows

    Default Change background color of QPushButton

    Hi all,
    I can change the text color of a QPushButton object using the QPalette::ButtonText attribute but I don't know how to change the background color of that button?
    I tried the QPalette::Button, QPalette::Background,... but nothing changes.
    Help me!
    Thanks very much!

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

    Default Re: Change background color of QPushButton

    QPalette::Button should have worked. You must have missed something while trying it. If it doesn't, maybe your QStyle doesn't allow changing the background colour of a button (I guess WindowsXP style can do such a thing).

  3. #3
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Change background color of QPushButton

    Quote Originally Posted by gtthang
    Hi all,
    I can change the text color of a QPushButton object using the QPalette::ButtonText attribute but I don't know how to change the background color of that button?
    I tried the QPalette::Button, QPalette::Background,... but nothing changes.
    Help me!
    Thanks very much!
    Well it works fine for me....on WinXP and SuSE 9/10

    here's my snippet

    Qt Code:
    1. QPalette pal=palette(); //get button palette
    2. pal.setBrush(QPalette::Button,Qt::black); //makes my button black
    3. pal.setBrush(QPalette::ButtonText, Qt::white);
    4. mybutton.setPalette(pal);
    To copy to clipboard, switch view to plain text mode 

    I presume you are doing the same...I am just confirming it's working!

    Nupul

  4. #4
    Join Date
    Nov 2013
    Posts
    1
    Qt products
    Qt4 Qt5

    Default Re: Change background color of QPushButton

    I am using the exact same piece of code as mentioned. But only my text colour is changing to black. My button colour does not change. I am using Qt Creator 2.8.1 Based on Qt 5.1.1. Any suggestions ?

    1. QPalette pal=palette(); //get button palette
    2. pal.setBrush(QPalette::Button,Qt::black); //makes my button black
    3. pal.setBrush(QPalette::ButtonText, Qt::white);
    4. mybutton.setPalette(pal);

Similar Threads

  1. Change QPushButton Background Color, Qt4.3
    By Rayven in forum Qt Programming
    Replies: 5
    Last Post: 4th July 2009, 07:14
  2. how to change QTextEdit background color ?
    By mismael85 in forum Qt Programming
    Replies: 9
    Last Post: 26th June 2008, 22:05
  3. Trying to change the background of a QTreeWidget
    By vycke in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2008, 20:44
  4. How to change color of a QPushButton?
    By vishal.chauhan in forum Qt Programming
    Replies: 6
    Last Post: 5th March 2008, 13:22
  5. Change background color for a QPushButton?
    By Harvey West in forum Qt Programming
    Replies: 6
    Last Post: 5th January 2007, 14:23

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.