PDA

View Full Version : Change background color for a QPushButton?



Harvey West
5th January 2007, 13:12
Hello

Want to change background color for a QPushButton.
Is there an easy switch to do this?

i.e. create a QDialoge with red green & blue QPushButton widgets.

munna
5th January 2007, 13:27
If you are using Qt 4.2 then Qt Style Sheets (http://doc.trolltech.com/4.2/stylesheet.html) is the best way to do this.
Otherwise, you can use QPalette (http://doc.trolltech.com/4.2/qpalette.html) to change the background color of the button.

wysota
5th January 2007, 14:03
Otherwise, you can use QPalette (http://doc.trolltech.com/4.2/qpalette.html) to change the background color of the button.

Ahh... the famous "red pushbutton" issue :)

Unfortunately QPalette approach will not work for WindowsXP and Aqua styles. The only thing you can do if you don't have Qt 4.2 is to use a proxy style (http://wiki.qtcentre.org/index.php?title=Proxy_Style) and change the way buttons are drawn (for example call the "Windows style" implementation for "WindowsXP style" and "Plastique" implementation for Aqua).

munna
5th January 2007, 14:30
Ahh... the famous "red pushbutton" issue :)

Right. I just finished watching the video (http://www.trolltechvideo.com/video/day2/room_a/a_2_1/video.html).

wysota
5th January 2007, 15:01
Right. I just finished watching the video (http://www.trolltechvideo.com/video/day2/room_a/a_2_1/video.html).

If you look closely you can probably see Dani's (theLSB) back (not sure if it's in this video) and if you turn up the volume you might hear him or me as well (definitely this video). Unfortunately the background sound is almost impossible to hear so the chance of hearing any of us asking questions is pretty tiny :)

BTW. There is an article by Girish on style sheets in the latest Qt Quarterly issue - I just took it out of my mailbox today :)

munna
5th January 2007, 15:15
If you look closely you can probably see Dani's (theLSB) back (not sure if it's in this video) and if you turn up the volume you might hear him or me as well (definitely this video). Unfortunately the background sound is almost impossible to hear so the chance of hearing any of us asking questions is pretty tiny :)

No, I cannot hear any of you.:( I think its the place where Girish says he will explain it in the later slides. Right?


BTW. There is an article by Girish on style sheets in the latest Qt Quarterly issue - I just took it out of my mailbox today :)

I am not able to find it on the Qt Quarterly site. Can you please post the link ?
BTW, how can we subscribe for Qt Quarterly ?

Thanks a lot.

wysota
5th January 2007, 15:23
No, I cannot hear any of you.:( I think its the place where Girish says he will explain it in the later slides. Right?
I don't remember right now. We were sitting in the front row on the left side of the room. I remember Dani was asking some question about transparency of the buttons but the lecturer didn't exactly understand the question. After the presentation they talked about it and Girish came to a conclusion that Dani was right and that he'll consider his suggestion. Dani was proud... :D


I am not able to find it on the Qt Quarterly site. Can you please post the link ?
BTW, how can we subscribe for Qt Quarterly ?
It's not available online yet. I'm talking about the printed version. I don't think you can "subscribe" for it.

The stylesheet article contains about the same content as the DevDays presentation, some of the pictues are even the same :)

Ok, we're much offtopic here :)