PDA

View Full Version : using setStyleSheet



Weilor
13th September 2007, 11:53
Hi all,

I change the background color of my QPushButtons dynamically using Style Sheets:

button->setPalette(QPalette(color));
#ifdef Q_OS_WIN
button->setStyleSheet( QString("background-color: %1;"
"border: 2px solid #8f8f91; "
"border-radius: 6px;"
"min-width: 80px;" ).arg( color.name() ) );
#endif
If I want to use the same approach to get another color for the pressed-state of a button, what is the right syntax to achieve it (and without having an extra text file mybutton.css)?

Greets,
Weilor

wysota
13th September 2007, 12:01
* { ...}
:pressed { ... }

Better yet apply that on the parent or on the application object and use class or id selectors to select the object you want.

Weilor
13th September 2007, 13:52
Thanks wysota,


Better yet apply that on the parent or on the application object and use class or id selectors to select the object you want.

And why?

Greets,
Weilor

wysota
13th September 2007, 15:11
Because you'll have more control. Doubts like this one wouldn't even occur, because you'd be calling the object by name.

dyams
3rd January 2008, 07:13
Hi wysota! ;)

If I want to change only the font color of a widget by using stylesheets,

say i write it like this

this->setStyleSheet("color: red");

and this works fine.

but unfortunately if the font like bold, italic, underline... are set to true while calling the
setStyleSheet(..); I notice that font is loosing all those attributes like bold, underline, italic....

Is it a limitation of style sheets.

AFAIK, stylesheets are not good enough. because, if you are interested in changin only the font color, why should one worry about the other attributes like font bold, italic....?

desch
3rd January 2008, 10:04
Hi Diams,

You should read the doc and see that if you use style sheet, it erases everything from QPalette
and setFont is at the same level as QPalette ( don't ask exactly how does it work)

but you should take the choice between Qpalette and style sheet

for font bold:


QLabel{color:blue; font:bold;}

that's all

david

dyams
3rd January 2008, 10:59
Hi David


it erases everything from QPalette
This implementation is not a good idea, isn't it?

Thanks for the reply

desch
3rd January 2008, 11:32
Using style sheet seems the best and powerful way

otherwise from the doc its is said:

Do not use this function(setPalette()) in conjunction with Qt Style Sheets. When using style sheets, the palette of a widget can be customized using the "color", "background-color", "selection-color", "selection-background-color" and "alternate-background-color".

dyams
18th January 2008, 06:06
how to set the text underline property by using stylesheets?

QLabel {color:blue; font:bold;}

the above example works fine for foreground color and font bold attributes.
But I couldn't see anywehere in Qt documentation about how to set the underline attribute.

Could anyone help me please?
-James

dyams
18th January 2008, 08:58
so, there is no way we can set the
{ font : underline; } attribute through stylesheets???

NOTE: { font : underline; } fails. This is not the right way of doing it.

But i dont know the right way either.

wysota
18th January 2008, 11:02
I don't know if Qt supports it, but in CSS it should be "text-decoration: underline;" as far as I remember.

jameleon
18th January 2008, 14:41
I don't know if Qt supports it, but in CSS it should be "text-decoration: underline;" as far as I remember.

Yes, Qt4.3.x support the most syntax of CSS2, including the "text-decoration: underline;" as you posted:)