PDA

View Full Version : QPushButton stylesheet problem



blukske
24th August 2009, 13:52
Whenever I set a stylesheet on a QPushButton, the button's appearance changes unexpectedly when running the application. For example, using the following stylesheet:



color: red;


Every looks fine in Qt Designer:

http://img229.imageshack.us/img229/9631/designerz.png

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

http://img229.imageshack.us/img229/692/window.png

This is using Qt 4.5.2. How do I fix this?

Lykurg
24th August 2009, 14:24
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.

blukske
24th August 2009, 15:26
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?

blukske
24th August 2009, 15:34
To illustrate, this is how a button with input focus looks in case no stylesheet has been set (the upper button has input focus):

http://img228.imageshack.us/img228/8099/normalm.png

Lykurg
24th August 2009, 18:36
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

ntp
24th August 2009, 21:16
You can add a pressed and hover state to your style sheet to make it behave as you wish

QPushButton { ... }
QPushButton:pressed {...}
QPushButton:hover {...}
QPushButton:disabled {...}

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

blukske
24th August 2009, 21:20
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



color: red;


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.

blukske
24th August 2009, 21:22
You can add a pressed and hover state to your style sheet to make it behave as you wish

QPushButton { ... }
QPushButton:pressed {...}
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.

blukske
24th August 2009, 21:25
These are the images that were posted above.

Lykurg
24th August 2009, 21:47
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?

blukske
24th August 2009, 21:51
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.