PDA

View Full Version : Setting stylesheet for "almost" all widgets



maverick_pol
3rd April 2008, 02:42
Hi,

I want to set my widgets' background color to black and text color to gray.


qApp->setStyleSheet(QString("QWidget {background: black; color: gray;}


BUT...

there are some widgets(about 4 or 5 classes) for which I do not want to set the new colors.

How to exclude those classes?

Thanks for any hint.

Kacper

jpn
3rd April 2008, 07:28
How about setting explicitly an empty style sheet for those widgets to be excluded?

maverick_pol
3rd April 2008, 08:34
Sounds good. Will try it.
Will this work?


qApp->setStyleSheets(QString("QWidget: { color: red}; MyClass: {color :blue};"));

I tried setting ' { } ' for one of the classes and this do not work.
I also tried setting(just after qApp->...):


myobject->setStyleSheet(QString(""));

Do not work as well.

What do you mean by "empty style sheets"?

Kacper

jpn
3rd April 2008, 08:49
Yeah, an empty string was exactly what I had on my mind...

maverick_pol
3rd April 2008, 08:54
Ok, but this solution do not work.

Kacper

GuS
8th April 2008, 19:08
I have same behavior here:

I am applying a general stylesheets for all widgets. But what i want is that for some kind of same widgets to have another style. So I applied a different stylesheet to those widgets and does not work... it just continue using the general applied stylesheet.

A Clear Example: I have forms buttons on all over my app so i use a general stylesheet for all those buttons, but i have some buttons that i use for menus/toolbar/etc. that i wish to set a different style, but when i write the stylesheet for those buttons, it still continue using the one applied before. Why?

Is this possible with Qt4?

Cheers.

phillip_Qt
9th April 2008, 07:18
How about setting explicitly an empty style sheet for those widgets to be excluded?

Hi.
I ve same problem like u. Can u plz tell me how to set default style sheet?
I tried like setStyleSheet(QString(""));
But its not working. My code is as follows


void NightColor()
{
ptr->LoadStyleSheet("Night");

}
void DayColor()
{
setStyleSheet(QString(""));

}

void Toggle()
{
if(m_iFlag == 0)
NightColor();
else
DayColor();
}


I ve a push button. if i press it 1st time Nightcolor() ll b called. But if i ll press nxt time default style sheet shd be activated. but its not activating.

maverick_pol
10th April 2008, 01:17
hi,

StyleSheets("");
does nothing. It do not work as nothing is being done. Even the "default" style sheet should contain that "default" settings.

Kacper

chuckshaw
28th May 2008, 19:56
In my app, I set a global style sheet for the entire app. For specific plugins I will set style sheets on them took look like I want. If you set an empty style sheet on a child widget, the parents style sheet will be applied. This is at least the behavior i see with Qt 4.4. I use this to set a style on say a button when an event happens and when the user acknowledges the button by clicking on it, i will set the style sheet to empty to set the look an feel back to that of the parent.

I would suggest that for a quick fix, just explicitly name the objects you want to apply the style sheet to instead of applying it globally. You can also apply the style sheet globally but you will have to specifically set a style sheet for those objects you want to appear different. You can't just set it to empty.

ex:
#ObjectName1 QWidget,
#ObjectName2 QWidget {
...
}

chuckshaw
28th May 2008, 19:59
Hi.
I ve same problem like u. Can u plz tell me how to set default style sheet?
I tried like setStyleSheet(QString(""));
But its not working. My code is as follows


void NightColor()
{
ptr->LoadStyleSheet("Night");

}
void DayColor()
{
setStyleSheet(QString(""));

}

void Toggle()
{
if(m_iFlag == 0)
NightColor();
else
DayColor();
}


I ve a push button. if i press it 1st time Nightcolor() ll b called. But if i ll press nxt time default style sheet shd be activated. but its not activating.

From the look of your code, You are setting a empty style sheet on the global object and not on your "ptr" object. Since the ptr object now has a style, it takes precidence over a global style. To set that object back to "default" use ptr->setStyleSheet("");

GuS
14th July 2008, 23:06
Guys... any tip for this?

Since in my app i have many (example) QPushButtons that follows a common style, but i have many others that have a different style.
So, an annoying solution was to set the style for ALL buttons using the object names of each one... but if you have many buttons? and what about dialogs created with QMessageBox or worst... a Print Dialog or Print Preview Dialog? you cant know the buttons objects names to style...

I thinks this is a problem in Qt, and stylesheets should be applied for general style like QPushButton {style} and for each different style using it object name like QPushButton#button {style}... That of course this does not work, since one will override the other...

Any help here? or is impossible ?

Thanks in advance...

Cheers.



I have same behavior here:

I am applying a general stylesheets for all widgets. But what i want is that for some kind of same widgets to have another style. So I applied a different stylesheet to those widgets and does not work... it just continue using the general applied stylesheet.

A Clear Example: I have forms buttons on all over my app so i use a general stylesheet for all those buttons, but i have some buttons that i use for menus/toolbar/etc. that i wish to set a different style, but when i write the stylesheet for those buttons, it still continue using the one applied before. Why?

Is this possible with Qt4?

Cheers.