PDA

View Full Version : why StyleSheet color setting changine button shape?



vonCZ
9th April 2009, 19:18
Hey, I'm trying to do a rather simple thing: control the color of my QPushButtons when isUp, isDown, hover, etc. I'm doing this:




myPb->setStyleSheet("QPushButton { background: rgb(230,230,230)}");



which works, but changes the shape & look/feel of the buttons from normal to rectangular... best explained by looking at the attached image. "Co2 Hist" and "Co2 Proj" are the buttons with the setStyleSheet functions. The others are left alone/default.

Can anyone suggest the simplest way to simply have the buttons look as they normally do, but with my own custom colors?

wysota
9th April 2009, 23:29
Because regular XP and Vista buttons don't support setting colours. So if the colour is to be set, an artificial button style has to be used. This is the case not only with Qt but with XP and Vista in general. See a web browser with a form that has a coloured button.

vonCZ
10th April 2009, 09:09
OK, so when "artificial button style" used: why does it look so different from the winXP style? What can I do to make it look like the winXP style?


The real problem: the button colors in their original format are fine, but people are complaining to me that they cannot tell sometimes whether a button (QPushButton) is pushed or not. So all I really want to do is make a pushed button look a little darker... so that it will stand out more as being pushed. Any advice appreciated.

wysota
10th April 2009, 14:49
OK, so when "artificial button style" used: why does it look so different from the winXP style?
Because the winxp style reacts on native skins that may be applied to it on the system level. There is no way Qt could emulate it all without extra effort. And there is no emulation on the system level for it. Blame Microsoft :)


What can I do to make it look like the winXP style?
You can style it yourself using images. But this won't emulate skins so if you deploy your application on a system with a different skin active, your button will still look odd.



The real problem: the button colors in their original format are fine, but people are complaining to me that they cannot tell sometimes whether a button (QPushButton) is pushed or not. So all I really want to do is make a pushed button look a little darker... so that it will stand out more as being pushed. Any advice appreciated.

How about implementing your own widget style or using one of the other widget styles available? Try running your application with "-style plastique" or "-style cleanlooks" parameters and see if it suits your needs.