PDA

View Full Version : Using stylesheets without loosing the whole style?



smoon
12th March 2011, 22:23
Hi,

is it possible to use stylesheets without loosing the whole style of the element? I find it kind of annoying, if I want to change little things like background or border of a widget that I have to rewrite the complete style.

Lykurg
12th March 2011, 23:06
No there isn't. But if you only want to change the background or any other single color role, try to use QPalette. It is very simple and most time better then applying a style sheet.

smoon
12th March 2011, 23:10
Unfortunately it's not always possible. E.g. for Buttons under Vista/Win 7...

wysota
12th March 2011, 23:19
Blame the OS provider.

smoon
13th March 2011, 00:17
Blame the OS provider.

It's not helpfull...

wysota
13th March 2011, 00:22
It's not helpfull...

Maybe if enough people write to M$ that they want to be able to change background color of buttons, the vendor will supply a patch allowing one to do this. So far this is simply not possible.

SixDegrees
13th March 2011, 00:37
Maybe if enough people write to M$ that they want to be able to change background color of buttons, the vendor will supply a patch allowing one to do this. So far this is simply not possible.

Given that it IS possible using stylesheets, it doesn't seem unreasonable for Qt to provide basic functions that leverage SS infrastructure to offer simple functions like setBackground(), setForeground() and so forth. These are everyday needs that are just that simple in other languages and frameworks, and are needlessly complex (or worse, impossible) in Qt.

wysota
13th March 2011, 00:49
Given that it IS possible using stylesheets
Actually it's not. The moment you start using stylesheets, you lose all style decorations. You can even see that in Internet Explorer when browsing a webpage that has a button with a modified color. It will look totally different from a button without a custom background.


These are everyday needs that are just that simple in other languages and frameworks, and are needlessly complex (or worse, impossible) in Qt.
It's not about Qt, it's about Windows' style API. Show me one theme-compliant button on Windows XP/Vista/7 with a red background (provided of course the system theme has a different background color by default).

SixDegrees
13th March 2011, 00:59
Actually it's not. The moment you start using stylesheets, you lose all style decorations. You can even see that in Internet Explorer when browsing a webpage that has a button with a modified color. It will look totally different from a button without a custom background.


It's not about Qt, it's about Windows' style API. Show me one theme-compliant button on Windows XP/Vista/7 with a red background (provided of course the system theme has a different background color by default).

Maybe I wasn't clear. It is entirely possible to control any aspect of button styling you like using stylesheets; the downside is that you have to reinvent the entire style to do so. Given that this is possible, however, it is also entirely possible to provide single-item control over those settings via Qt. In fact, the original versions of Qt did just that, providing simple setBackground(), setForeground(), etc., functions in addition to the more complex palette setting interface that now dominates. That's because originally, Qt did what Java did - it handled it's own drawing instead of relying on variable native GUI elements.

But it would be simple to return to such control through the use of the stylesheet mechanism, hiding the drudgery of complete style definition behind a function call where only a single attribute was modified.

wysota
13th March 2011, 01:15
That's because originally, Qt did what Java did - it handled it's own drawing instead of relying on variable native GUI elements.
Qt still does that for all styles but XP/Vista/7/Mac.


But it would be simple to return to such control through the use of the stylesheet mechanism, hiding the drudgery of complete style definition behind a function call where only a single attribute was modified.
This fails immediately if the user uses a different theme than the one which is implemented by Qt. You can't possibly emulate complete behaviour of the original theme with stylesheets. For instance you can't do animations whereas the system theme can. There were ideas to introduce animations in QStyle (or somewhere inside it) but then Nokia took over and apparently it wasn't so important anymore.

SixDegrees
13th March 2011, 13:21
Simple settings like chaging the background and foreground, however, are easily accomplished. We've done that with our own button extension, which has such functions and internally manipulate a stylesheet to get there.

At the end of the day, "Go talk to Microsoft" has far less traction than "Go talk to Nokia."

wysota
13th March 2011, 17:56
Simple settings like chaging the background and foreground, however, are easily accomplished.
So how do you make a button with a red background and the rest of the style following say... Mac or Windows XP theme?