Results 1 to 5 of 5

Thread: QPushButton, different stylesheets for focus/pressed/released combinations.

  1. #1
    Join Date
    Sep 2010
    Posts
    28
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default QPushButton, different stylesheets for focus/pressed/released combinations.

    I'm trying to accomplish some QPushButton-stylechanges, and need some help.

    My aim is the following behaviour

    Button Idle: White text on grey background
    Button Pressed: White text on blue background
    Button Idle+Focused: White text on grey background, border around it.
    Button Pressed+Focused: White text on blue background, border around it.

    I know how to create the mentioned looks using style sheets, but I'm not sure how to make it all come together.

    As a test I did the following in a test application:
    QPushButton { background-color: grey; }
    QPushButton:focusressed { background-color: black; }
    QPushButton:focus { background-color: green; }

    That worked quite well, except that my button had focus by default, without me really understanding why. Could I reach my goal doing something similar?

    How do I press/release a button and focus/unfocus it in my code? I tried calling click() without seeing any difference, but that might have been because of errors in my stylesheet I guess.

  2. #2
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Thanks
    6
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPushButton, different stylesheets for focus/pressed/released combinations.

    Make sure you have at least two buttons on your form when testing this.
    Otherwise you won't see any difference between a button having the focus and one not having it.

  3. #3
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: QPushButton, different stylesheets for focus/pressed/released combinations.

    hi mate,

    As far as I understand, you are suffering to have a button which probably on another widget of yours. If the problem is only appearing focused at first, all you need to do is unfocusing. boudie's suggestion is simple and clear I guess.

  4. #4
    Join Date
    Sep 2010
    Posts
    28
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QPushButton, different stylesheets for focus/pressed/released combinations.

    Thanks. A little more style-sheet-education on my part and it works.

  5. #5
    Join Date
    Jan 2011
    Posts
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPushButton, different stylesheets for focus/pressed/released combinations.

    I also tried the following:
    QPushButton{ background-color: blue; }
    QPushButton:disabled{ background-color: yellow; }
    QPushButton:pressed{ background-color: orange; }
    QPushButton:focus:pressed{ background-color: black; }
    QPushButton:focus{ background-color: green; }
    QPushButton:hover{ background-color: red; }
    QPushButton:checked{ background-color: pink; }

    I see the blue, red, green, pink, and black mostly as expected. I do not have a disabled button, but would expect that to work. What I am trying to figure out is when the button is checked (has the focus or does not have the focus), how do I NOT have the checker board background?

Similar Threads

  1. Replies: 10
    Last Post: 27th February 2010, 09:16
  2. Replies: 4
    Last Post: 19th February 2010, 07:23
  3. MenuBar grabs the focus on ALT pressed.
    By Cutey in forum Qt Tools
    Replies: 7
    Last Post: 16th January 2007, 09:59
  4. MenuBar grabs focus on ALT pressed.
    By Cutey in forum Qt Programming
    Replies: 2
    Last Post: 9th January 2007, 11:45
  5. Replies: 3
    Last Post: 26th September 2006, 12:16

Tags for this Thread

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.