Results 1 to 4 of 4

Thread: Setting color of checked toggle button

  1. #1
    Join Date
    Jul 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Setting color of checked toggle button

    My first foray into Qt land using python and pyqt. I've created a toggle button and I'm able to set its unchecked colors:

    Qt Code:
    1. self.DCButton.setStyleSheet("color: black; background-color: red;")
    To copy to clipboard, switch view to plain text mode 
    My problem is setting the button color when its "checked":

    Qt Code:
    1. self.DCButton.setStyleSheet(QPushButton#DCButton:checked {"color:black; background-color: green;}")
    To copy to clipboard, switch view to plain text mode 

    doesn't work. I'm sure this is a simple syntax problem.

    TIA

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Setting color of checked toggle button

    Python should be telling you this is an error:
    Qt Code:
    1. self.DCButton.setStyleSheet(QPushButton#DCButton:checked {"color:black; background-color: green;}")
    To copy to clipboard, switch view to plain text mode 
    try:
    Qt Code:
    1. self.DCButton.setStyleSheet("QPushButton#DCButton:checked {color:black; background-color: green;}")
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Setting color of checked toggle button

    Thanks for the reply and sorry for the typo. I've moved the quote to the correct spot in the call, but my problem persists. If I just use the first line, the button reacts correctly (although it uses the default color when checked). When I include the second line, the button reverts to its default colors and behavior:

    Qt Code:
    1. self.DCButton.setStyleSheet("color: black; background-color: rgb(3,100,226);")
    2. self.DCButton.setStyleSheet("QPushButton#DCButton:checked {color: black; background-color: green;")
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Setting color of checked toggle button

    Have a look at the note regarding styling the background of a QPushButton Qt Style Sheets Reference
    Qt Code:
    1. QPushButton#DCButton:checked {color: black; background-color: green; border: none; }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. How can I get System setting color
    By dpatel in forum Qt Programming
    Replies: 2
    Last Post: 20th July 2010, 09:20
  2. Change button Icon on toggle
    By bizmopeen in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2009, 00:17
  3. Replies: 3
    Last Post: 10th April 2009, 15:49
  4. Replies: 8
    Last Post: 2nd February 2009, 13:25
  5. how to change backgroup color, button color and shape?
    By lzha022 in forum Qt Programming
    Replies: 10
    Last Post: 16th June 2008, 23:25

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.