Results 1 to 20 of 28

Thread: QPushbutton background color

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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.

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

    Default Re: QPushbutton background color

    visual studio 2005 + XP !

  3. #3
    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)

  4. #4
    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;}");

  5. #5
    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

  6. #6
    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.

  7. #7
    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

  8. #8
    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

  9. #9
    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.

  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 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?

  11. #11
    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

  12. #12
    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

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

    Default Re: QPushbutton background color

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

    yes.. done

    thank u very much

  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

    I'm talking about this
    Qt Code:
    1. ....
    2. QPixmap pixmap(width, height);
    3. pixmap.fill(Qt::red);
    4. QIcon icon(pixmap);
    5. ...
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QPushbutton background color

    sorry I read it quickly
    ok that is better

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