Results 1 to 9 of 9

Thread: QColor PushButton

  1. #1
    Join Date
    Jun 2009
    Posts
    10
    Platforms
    MacOS X

    Default QColor PushButton

    I am wondering if anyone can assist me in changing the color of a button upon it being on and and off. so for example - when it is on its green however when it is off it is red.

    I think in the older version of qt the QPushButton isOn assisted in this.
    I have proved an example:

    if (button->isDown())
    button->setStyleSheet(QString("QPushButton {background-color: green;}"));
    else
    button->setStyleSheet(QString("QPushButton {background-color: red;}"));
    }

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QColor PushButton

    Hi, have a look on the Pseudo-States of the qt style sheets!

    (setCheckable() with : on)

  3. #3
    Join Date
    Jun 2009
    Posts
    10
    Platforms
    MacOS X

    Default Re: QColor PushButton

    Could you possibly explain, since I have looked at it and am a little confuse. Are you suggesting if(button->setCheckable()n)?

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

    Default Re: QColor PushButton

    More likely:
    css Code:
    1. QPushButton:pressed { background-color:green; }
    2. QPushButton { background-color: red; }
    To copy to clipboard, switch view to plain text mode 
    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.


  5. #5
    Join Date
    Jul 2009
    Posts
    39
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QColor PushButton

    How can I apply coloring for specific push buttons? For example

    QPushButton pushButton;

  6. #6
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QColor PushButton

    use pushbutton.setStyleSheet()...

  7. #7
    Join Date
    Jul 2009
    Posts
    39
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QColor PushButton

    pushButton->setStyleSheet("background-color: red")
    is ok for background, but how will I "pressed" part?

  8. #8
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QColor PushButton

    put everything in just one string... study the style sheet example that comes with qt

  9. #9
    Join Date
    Jul 2006
    Posts
    8
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QColor PushButton

    Qt Code:
    1. pushButton->setStyleSheet("QPushButton:pressed { background-color: blue; }");
    To copy to clipboard, switch view to plain text mode 

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.