Results 1 to 4 of 4

Thread: QPushButton with two states and colours

  1. #1
    Join Date
    Apr 2007
    Posts
    16
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QPushButton with two states and colours

    I need a pushbutton in GUI with two states. My requirements are as follows:-
    1. It should have ON and OFF states. On clicking it should toggle between both.
    2. When ON it should be in Red colour. When OFF it should be Green colour.
    3. In either state a different job has to be done.
    How can I implement this?

  2. #2
    Join Date
    Feb 2006
    Location
    Jarrell, Texas, USA
    Posts
    70
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QPushButton with two states and colours

    Review the setCheckable() method of the QPushButton class.

    Karl

  3. #3
    Join Date
    Apr 2007
    Posts
    16
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPushButton with two states and colours

    I tried this approach with me changing the Stylesheet in the toggled slot but the look I get is not what I want. I am expecting the buttons to look the way they do in the picture below in both states:-
    wanted.png
    However, second state looks like shown in top button here. It is embedded and colour is not coming properly like I expect in the button below. How do I get the correct red look as wanted?
    unwanted.png

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

    Default Re: QPushButton with two states and colours

    Subclass and reimplement paintEvent() to do your own painting.
    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.


Similar Threads

  1. Qt Creator Unreadable colours for Documentation
    By Ram-Z in forum Qt Tools
    Replies: 10
    Last Post: 11th March 2014, 14:29
  2. Alternate row colours in QFormLayout
    By xtal256 in forum Qt Programming
    Replies: 9
    Last Post: 27th February 2011, 22:36
  3. Replies: 1
    Last Post: 13th March 2008, 07:19
  4. QLabel colours
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 14th May 2007, 16:46

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.