Page 1 of 2 12 LastLast
Results 1 to 20 of 28

Thread: QPushbutton background color

  1. #1
    Join Date
    Jul 2008
    Posts
    40
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QPushbutton background color

    Hello to all,
    I wish to color the background of a button with RGB,

    ideas?

    Thank you

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPushbutton background color

    you can use style sheets or QPalette

  3. #3
    Join Date
    Oct 2008
    Posts
    70
    Thanks
    1
    Thanked 9 Times in 9 Posts

    Default Re: QPushbutton background color

    Hello!

    Try following as example:

    Qt Code:
    1. QPalette p = pb->palette();
    2. p.setColor(QPalette::Button, Qt::red);
    3. pb->setPlaette(p);
    To copy to clipboard, switch view to plain text mode 

    //where pb is QPushButton

  4. #4
    Join Date
    Jul 2008
    Posts
    40
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPushbutton background color

    I tried this code, but it just creates a red contour :s

    thanks

  5. #5
    Join Date
    Oct 2008
    Posts
    70
    Thanks
    1
    Thanked 9 Times in 9 Posts

    Default Re: QPushbutton background color

    Strange... It's working for me fine. What OS are you using?

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPushbutton background color

    yup, this code works fine.

  7. #7
    Join Date
    Jul 2008
    Posts
    40
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPushbutton background color

    visual studio 2005 + XP !

  8. #8
    Join Date
    Oct 2008
    Posts
    70
    Thanks
    1
    Thanked 9 Times in 9 Posts

    Default Re: QPushbutton background color

    Please show your code and screenshot (if possible of course)

  9. #9
    Join Date
    Jul 2008
    Posts
    40
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPushbutton background color

    this is the code :

    QPalette p = ui.pushButton->palette();
    p.setColor(QPalette::Button, Qt::red);
    ui.pushButton->setPalette(p);

    the screenshot is not big thing, just a buton for test


    ypp, I tried with sylesheet but the buton come not clickable:

    ui.pushButton->setStyleSheet ("QPushButton {background : rgb(224, 0, 0); border-width: 2px; border-radius: 10px; border-color: beige; font: bold 14px; min-width: 10em; padding: 6px;}");

  10. #10
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPushbutton background color

    try this example.
    Attached Files Attached Files

  11. #11
    Join Date
    Jul 2008
    Posts
    40
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPushbutton background color

    thank you for the example, it works just with :

    pushButton_2->setStyleSheet("QPushButton {background : rgb(224, 0, 0);}");


    The first button has not changed (QPalette)
    the second buton come not clickable
    Last edited by omega36; 30th October 2008 at 14:06.

  12. #12
    Join Date
    Jul 2008
    Location
    Bangalore
    Posts
    10
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Unix/X11

    Default Re: QPushbutton background color

    Hi i think this code is working properly..
    QPalette lPalette;
    lPalette.setColor(pb1->backgroundRole(),QColor(255,0,0));
    pb1->setPalette(lPalette);
    the above code is correct and u try it...
    where pb1 is ur pushbutton

  13. #13
    Join Date
    Jul 2008
    Posts
    40
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPushbutton background color

    even if the above code is correct, but... nothing happend

    and this is my solution : I create a red .png - for exemple - with "MacromediaFireWorks" ,
    I convert it to .ico and it's work with this code :

    ui.pushButton->setIcon(QIcon("./icon/28.ico"));

    thanks to all

  14. #14
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPushbutton background color

    it's not a solution. it's woraround. you have to find a problem.

  15. #15
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPushbutton background color

    try to de the next thing, open Qt Designer, create a widget and put on it a QPushButton and play with a palette settings of this button. what will you see?

  16. #16
    Join Date
    Jul 2008
    Posts
    40
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPushbutton background color

    I dont see any thing
    it's a temporary solution

  17. #17
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPushbutton background color

    did you do this in designer and color of button did not change?
    ps. packed by 7zip
    Attached Files Attached Files

  18. #18
    Join Date
    Jul 2008
    Posts
    40
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPushbutton background color

    I did the same..
    even on the pallette all other controls change color except button

  19. #19
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPushbutton background color

    rebuild Qt and try again

  20. #20
    Join Date
    Oct 2008
    Posts
    70
    Thanks
    1
    Thanked 9 Times in 9 Posts

    Default Re: QPushbutton background color

    omega36, what version of Qt are you using?

Similar Threads

  1. Change background color of QPushButton
    By gtthang in forum Qt Programming
    Replies: 3
    Last Post: 26th November 2013, 10:23
  2. Change QPushButton Background Color, Qt4.3
    By Rayven in forum Qt Programming
    Replies: 5
    Last Post: 4th July 2009, 07:14
  3. How to change color of a QPushButton?
    By vishal.chauhan in forum Qt Programming
    Replies: 6
    Last Post: 5th March 2008, 13:22
  4. Change background color for a QPushButton?
    By Harvey West in forum Qt Programming
    Replies: 6
    Last Post: 5th January 2007, 14:23
  5. QLabel background color
    By munna in forum Newbie
    Replies: 3
    Last Post: 1st May 2006, 15:36

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.