PDA

View Full Version : QPushButton in QDockWidget loses stylesheet



martinb0820
4th June 2009, 20:04
I have a QPushButton in a QDockWidget, and am setting the color of the push button using a simple stylesheet ("background-color:green").

This works fine except that, when the QDockWidget containing the push button is undocked, the pushbutton reverts to its default color.

I could subclass the QDockWidget, catch the topLevelChanged() signal, and change the push button's color to what it should be, but it seems like that shouldn't be necessary...

Any ideas?

Thanks,
Martin

Lykurg
4th June 2009, 20:46
I could subclass the QDockWidget, catch the topLevelChanged() signal, and change the push button's color to what it should be, but it seems like that shouldn't be necessary...
This should really not be necessary, but with a quick test in designer I couldn't reproduce your problem. So could you make a minimal example reproducing your problem?

Otherwise using the palette for simple background color change can solve your problem.

wysota
4th June 2009, 21:47
Otherwise using the palette for simple background color change can solve your problem.

Unless you're using WindowsXP, Vista or Mac styles, of course.

martinb0820
4th June 2009, 22:07
Hi Lykurg,

Thanks for trying it in Designer. I tried that after reading your reply, and it works in Designer's Form --> Preview, but doesn't work in the actual software...

For what it's worth, the development environment is Visual Studio 2005 and the test system is XP. I'm using the commercial version of Qt 4.5.1.

Could it be a bug in either Qt or XP?

Martin

wysota
4th June 2009, 22:10
Could you provide a minimal compilable example reproducing the problem?

martinb0820
22nd June 2009, 18:23
I changed the stylesheet, and it works. Originally, one stylesheet specified the down and up appearance of the QPushButton. I changed the code to switch between two stylesheets, each of which specifies a different background-color, without specifying in the stylesheet whether the QPushButton is up or down. This works fine.