Results 1 to 2 of 2

Thread: QPushButton BackColor

  1. #1
    Join Date
    Apr 2010
    Posts
    13
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default QPushButton BackColor

    I would like to change a backcolor theme of a QPushButton being Pressed. I am using QT Creator 2 and Windows 7. Here is the code. I tried using the StyleSheet option and it works fine, but in this case I will have a color dialog that will return the color that the button will need to change to. I would like the color not be solid, but gradient like it is by default but with a different themeColor.

    Qt Code:
    1. QPushButton *button = this->findChild<QPushButton *>(text);
    2. if ( button->text() != "Pressed")
    3. {
    4. button->setText("Pressed");
    5.  
    6. QColorDialog *myColorDialog;
    7. QColor theColorPicked;
    8. QPalette thePal;
    9.  
    10. theColorPicked = myColorDialog->getColor(QColor(0,0,0));
    11. thePal.setColor(button->backgroundRole(),theColorPicked);
    12. button->setPalette(thePal);
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QPushButton BackColor

    Windows7 cannot render a button with a different colour so you will lose your native decoration anyway and the only way you can do it with Windows7 style is through stylesheets.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following 2 users say thank you to wysota for this useful post:

    axisdj (21st September 2010), pakine (27th October 2010)

Similar Threads

  1. Replies: 0
    Last Post: 22nd February 2010, 09:30
  2. QPushButton
    By anafor2004 in forum Newbie
    Replies: 1
    Last Post: 21st October 2009, 16:31
  3. How to set my QPushbutton's background?
    By cspp in forum Qt Programming
    Replies: 18
    Last Post: 24th April 2009, 15:23
  4. Qpushbutton
    By iamhere in forum Qt Programming
    Replies: 5
    Last Post: 15th October 2008, 04:40
  5. Replies: 3
    Last Post: 26th September 2006, 12:16

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.