PDA

View Full Version : Stylesheet secondary effects



frank100
25th January 2011, 21:15
I am maintaining an existing application for which I want to start using a custom stylesheet. My first trial only defines the background color for a single widget (combobox pushbutton).

QPushButton#evilButton {
background-color: red;
}

Since I am planning to add many more cases like this I set the stylesheet to the main window.

Now, to my surprise using that simple stylesheet does not only change the color of my button, but also its size and the arrow that marks the combobox option. I have not defined a global QPushButton {...} entry, but my evilButton shape looks clearly different from all the other buttons.

How can I make the above entry to change just the color?

wysota
25th January 2011, 21:24
You can't.

frank100
25th January 2011, 21:55
wow! you've just killed all the joy. I did some web programming and I loved the idea of CSS taking away the presentation information from the code.

Now having QPushButton#evilButton {..} inheriting from a QPushButton different from the one that the rest of the application is using seems strange.

My plan B was defining on run time my own QPushButton stylesheet and extract the info from a dummy pushbutton. At least that should solve the issue where the autogenerated QPushButton does not match the one from the system :-(

I hope Qt fixes that issue within a future! Or is there a reason for that?

wysota
25th January 2011, 22:41
wow! you've just killed all the joy.
Sorry... life sometimes sucks.


I did some web programming and I loved the idea of CSS taking away the presentation information from the code.
Web CSS works in a different way that widget CSS. The latter is an artificial QStyle subclass so when you enable stylesheets for a widget, its style changes to the artificial one so all things drawn customly by your "main" style are gone and you're left with a "naked" widget that you need to "dress". Sometimes the bare stylesheet style output is close to the one provided by the real style and sometimes it is not.


I hope Qt fixes that issue within a future! Or is there a reason for that?
It's not that easy. Qt4 will definitely not do that. You would have to have some kinds of hooks for stylesheets in all possible style implementations and the API itself. So essentially stylesheets would have to be drawn by the true style (which is impossible for the "system" styles such as Aqua, WindowsXP and similar) which defeats the purpose of stylesheets.