Empty style sheet and *.ui
-
If you mean this:
@HeaderWidget
{
background-color: red;
}@
This doesn't work.
And if by "name of your widget" you mean objectName() this won't work too since this problem appers not only for headers (which are, of course, single on every window) but for example for address boxes too (and window can contain many of them). -
[quote author="p-himik" date="1316849264"]The ugliest solution ever.
...
I have a feeling that i will burn in hell for this.[/quote]You will, because neither QObject::setObjectName() nor QWidget::setStyleSheet() is declared virtual, which means that both method implementations will be skipped when called through base class pointers.
[quote author="p-himik" date="1316853767"]If you mean this:
@HeaderWidget
{
background-color: red;
}@
This doesn't work.
[/quote]
But it should.
[quote author="p-himik" date="1316846718"]Can i somehow mark lines in the style sheet that they are relevant only to widget which invokes setStyleSheet() (so only w will have red background, no matter what object name it has)?[/quote]No, but you can use a "property selector":http://doc.qt.nokia.com/latest/stylesheet-syntax.html#selector-types to select single widget objects of the same type.
@
HeaderWidget
{
...
}
HeaderWidget[type="redBackgroundType"]
{
background-color: red;
}
HeaderWidget* widget = new HeaderWidget;
widget->setProperty("type", "redBackgroundType");
@ -
Can you show us a bitmap of what you want to accomplish. Eg. A screen shot of your ui file?
I don't understand why you are subclassing QWidget and not one of it's descendants that looks like what you want.
-
bq. You will, because neither QObject::setObjectName() nor QWidget::setStyleSheet() is declared virtual, which means that both method implementations will be skipped when called through base class pointers.
I know about absence of "virtual" modifier but these functions won't ever be called through base class pointers (even in ui_*.h file).
bq. But it should.
Here is a picture.
!http://dl.dropbox.com/u/26596688/notworking.JPG(useless style sheet for header widget)!Eddy, all i want is ability to create multiple widgets of the same my class on a single window. And style sheet for every widget must be defined globally (my previous approach was to just copy style sheet over and over. But that's sucks). The reason why i don't want to create Qt Designer's plugin is that appearance of my widget could be changed a few times per day.
Wherever i write style sheet for my widget it'll be overwritten by parent's style sheet with ui->setupUi( this ) call.
And i subclass QWidget because there is no other widget that looks the way i need (already mentioned address box. Separate fields for region, state, city, etc. And style sheet different from the rest of the widgets).bq. No, but you can use a property selector [doc.qt.nokia.com] to select single widget objects of the same type.
I'll try in a few minutes.
-
Forgot to mention - there is not only a window with multiple widget. There is multiple windows. So this style sheet have to be written in a place somehow related to HeaderWidget (i can assign it to QApplication, but it removes a great ability of WYSIWYG-like Qt Designer to show you changes as they are made).
[quote author="Lukas Geyer" date="1316855095"]No, but you can use a "property selector":http://doc.qt.nokia.com/latest/stylesheet-syntax.html#selector-types to select single widget objects of the same type.[/quote]
Tried. Didn't work either which is logically since HeaderWidget's style sheet is overwritten by parent widget's .ui file independently of what properties i used.Again, overwriting with empty style sheet happens only when i press OK button in style sheet editor for widget promoted to HeaderWidget. If i don't touch anything (just place widget, adjust it's size and geometry and promote it to HeaderWidget) style sheet won't be overwritten and everything is OK.
Maybe it's worth to add a few lines to Qt Designer's sources so that it will remove "< property name="styleSheet">" completely from .ui file if there is no style sheet? Now it just places
@
< property name="styleSheet">
<string notr="true"/>
</property>@
there thus overwriting any style sheet provided by HeaderWidget.And why reply editor removes "< property name="styleSheet">" when there is no space after left bracket?
-
I think we have come at a stadium that it is better to make a small compilable example and show us the code. This can help to fine tune the problem.
-
-
I tried your code out and it works if you use it in main on the qapplication like this :
@int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setStyleSheet("CommonWidget { ......
MainWindow w;
w.show();return a.exec();
}@
I omitted the @,*[class="CommonWidget"] @
Now throughout your application if there is a commonWidget it will be styled using this stylesheet.
-
Eddy, thank you for your answer but i've written:
[quote author="p-himik" date="1316858503"]... (i can assign it to QApplication, but it removes a great ability of WYSIWYG-like Qt Designer to show you changes as they are made).[/quote]Of course if there is no other way to do it, i'll do it this way.
And i still sure that Qt Designer must not insert “< property name=“styleSheet”>” tag into the .ui file when there is no any style sheet set. -
Sorry i didn't see that.
Afaik stylesheets are not used the way you want. The power of stylesheets is exactly that you can give the whole of your application the same look in one place.