Results 1 to 11 of 11

Thread: QPushButton stylesheet problem

  1. #1
    Join Date
    May 2006
    Posts
    23
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QPushButton stylesheet problem

    Whenever I set a stylesheet on a QPushButton, the button's appearance changes unexpectedly when running the application. For example, using the following stylesheet:

    Qt Code:
    1. color: red;
    To copy to clipboard, switch view to plain text mode 

    Every looks fine in Qt Designer:



    But when I run the application I get the following result:



    This is using Qt 4.5.2. How do I fix this?
    Last edited by blukske; 24th August 2009 at 14:03.

  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: QPushButton stylesheet problem

    What's the problem? The color is red. Everything fine... In your final program your button has the focus and therefore the focus rectangle. If you don't like it, change it.

  3. The following user says thank you to Lykurg for this useful post:

    blukske (24th August 2009)

  4. #3
    Join Date
    May 2006
    Posts
    23
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPushButton stylesheet problem

    Thanks, the input focus indeed causes the rectangle. However, when I do not set any stylesheet, the input focus rectangle is not displayed when the button has focus. It seems that setting any custom stylesheet causes the input focus rectangle to be displayed when the button has input focus.

    How can I prevent this? Or, how should I adapt my stylesheet to ensure that the input focus rectangle is not displayed?

  5. #4
    Join Date
    May 2006
    Posts
    23
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPushButton stylesheet problem

    To illustrate, this is how a button with input focus looks in case no stylesheet has been set (the upper button has input focus):


  6. #5
    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: QPushButton stylesheet problem

    what style do you use? normally I only know a dashed or dotted rectangle as focus. And how does your complete style sheet looks like? May be you have there other settings causing your problem.

    And please add your images at the thread and not at a 3rd party site, so that your post stays consistent also in future.


    Lykurg

  7. #6
    Join Date
    Jul 2007
    Location
    California, USA
    Posts
    62
    Thanks
    17
    Thanked 7 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPushButton stylesheet problem

    You can add a pressed and hover state to your style sheet to make it behave as you wish

    QPushButton { ... }
    QPushButtonressed {...}
    QPushButton:hover {...}
    QPushButton:disabled {...}

    You probably want to put in
    color: red;
    background: (whatever color you want)

  8. #7
    Join Date
    May 2006
    Posts
    23
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPushButton stylesheet problem

    Quote Originally Posted by Lykurg View Post
    what style do you use? normally I only know a dashed or dotted rectangle as focus. And how does your complete style sheet looks like? May be you have there other settings causing your problem.

    And please add your images at the thread and not at a 3rd party site, so that your post stays consistent also in future.


    Lykurg
    I'm using Gnome, Ubuntu 9.04. If I understand correctly, Qt defaults to QGtkStyle in my case. For the application in the screenshots above, no other stylesheets have been specified anywhere except for the

    Qt Code:
    1. color: red;
    To copy to clipboard, switch view to plain text mode 

    part. So I expect it is buggy behaviour in the QGtkStyle that such a stylesheet causes a complete change in the input focus rectangle appearance. I'll file a bug for this case.

  9. #8
    Join Date
    May 2006
    Posts
    23
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPushButton stylesheet problem

    Quote Originally Posted by ntp View Post
    You can add a pressed and hover state to your style sheet to make it behave as you wish

    QPushButton { ... }
    QPushButtonressed {...}
    QPushButton:hover {...}
    QPushButton:disabled {...}

    You probably want to put in
    color: red;
    background: (whatever color you want)
    I may be able to mimick the default QGtkStyle behaviour, but in case the application runs in a different Gnome environment with different theme settings it's look will not be consistent with other applications. So I don't like this approach although it may work.

  10. #9
    Join Date
    May 2006
    Posts
    23
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPushButton stylesheet problem

    These are the images that were posted above.
    Attached Images Attached Images

  11. #10
    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: QPushButton stylesheet problem

    Quote Originally Posted by blukske View Post
    So I expect it is buggy behaviour in the QGtkStyle that such a stylesheet causes a complete change in the input focus rectangle appearance. I'll file a bug for this case.
    Have you tried an other style? The same there?

  12. #11
    Join Date
    May 2006
    Posts
    23
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPushButton stylesheet problem

    Quote Originally Posted by Lykurg View Post
    Have you tried an other style? The same there?
    Yes, I just tried QCleanlooksStyle and the problem did not occur. I assume now that QGtkStyle is the problem. I just filed a bug and will post the link here as soon as it is accepted.

Similar Threads

  1. Problem with QPrintPreviewWidget
    By nifei in forum Qt Programming
    Replies: 2
    Last Post: 25th March 2012, 01:18
  2. Replies: 1
    Last Post: 23rd April 2009, 09:05
  3. Replies: 19
    Last Post: 3rd April 2009, 23:17
  4. Replies: 1
    Last Post: 7th October 2007, 23:02
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.