Results 1 to 7 of 7

Thread: Change background color for a QPushButton?

  1. #1
    Join Date
    Nov 2006
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Change background color for a QPushButton?

    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.

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Change background color for a QPushButton?

    If you are using Qt 4.2 then Qt Style Sheets is the best way to do this.
    Otherwise, you can use QPalette to change the background color of the button.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 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 for a QPushButton?

    Quote Originally Posted by munna View Post
    Otherwise, you can use QPalette 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 and change the way buttons are drawn (for example call the "Windows style" implementation for "WindowsXP style" and "Plastique" implementation for Aqua).

  4. #4
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Change background color for a QPushButton?

    Quote Originally Posted by wysota View Post
    Ahh... the famous "red pushbutton" issue
    Right. I just finished watching the video.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 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 for a QPushButton?

    Quote Originally Posted by munna View Post
    Right. I just finished watching the video.
    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

  6. #6
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Change background color for a QPushButton?

    Quote Originally Posted by wysota View Post
    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?

    Quote Originally Posted by wysota View Post
    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.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 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 for a QPushButton?

    Quote Originally Posted by munna View Post
    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...

    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

Similar Threads

  1. Change background color of QPushButton
    By gtthang in forum Qt Programming
    Replies: 3
    Last Post: 26th November 2013, 10:23
  2. background colour
    By kw in forum Qt Programming
    Replies: 6
    Last Post: 11th April 2006, 00:44
  3. Replies: 1
    Last Post: 5th April 2006, 16:44

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.