Results 1 to 6 of 6

Thread: button background color when it is clicked

  1. #1
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Angry button background color when it is clicked

    Hi,
    I have placed some buttons which has seCheckable() state and SetAutodefault() state as true.

    I want to change the back ground color when it is active and when the button is pressed and down.

    I can change the color when it is active, but when it is clicked i want to change the background color of the button. i.e user should feel that button is pressed(down). when i use pressed or checked in my style sheet, the color changed only when mouse button is down.
    so how can i change the background color when button is down state.untill user press other button or the current button comes up, button color shouldnt change

    Thank You

  2. #2
    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: button background color when it is clicked

    try to use style sheets
    QPushButton:hover: pressed { color: blue; }
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: button background color when it is clicked

    I already used StyleSheets. Even i used QPushButton:hover: pressed { background-color: blue; }. Button will turn to blue when use press down and until mouse is in clicked state.. once you release the mouse it will be normal form.
    But i need to differentiate clicked state and normal state using background color.

    Thank You

  4. #4
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: button background color when it is clicked

    Can anyone help me out to resolve this

  5. #5
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: button background color when it is clicked

    try this

    Qt Code:
    1. QString style_sheet_btn =" QPushButton:checked {background-color:rgb(255,100,100);border-style:solid;border-width:1.5px;border-color:gray;}";
    To copy to clipboard, switch view to plain text mode 
    Jerry

  6. #6
    Join Date
    Jun 2024
    Posts
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: button background color when it is clicked

    Quote Originally Posted by calmspeaker View Post
    try this

    Qt Code:
    1. QString style_sheet_btn =" QPushButton:checked {background-color:rgb(255,100,100);border-style:solid;border-width:1.5px;border-color:gray;}";
    To copy to clipboard, switch view to plain text mode 
    See this <https://youtu.be/DwZ-B_ipmQY?si=nkvHz1obS0PLWOgL>

    Simply receive the button event and then change the style of the button that triggered the event using setStyleSheet() method

Similar Threads

  1. Replies: 10
    Last Post: 6th July 2008, 09:46
  2. Replies: 4
    Last Post: 29th February 2008, 10:04
  3. Replies: 3
    Last Post: 13th May 2007, 20:55

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.