Unsolved How to stop child dialogs from inheriting parent's StyleSheet
-
I have many dialogs in my application and I use StyleSheet functionality for them.
And also I have several auxiliary dialogs like Warnings, Messages, Progress Bars.
They can have their own StyleSheets or not. But they have concrete design which I set in QtDesigner.I want to invoke auxiliary dialogs from other dialogs, pointing them as a parent.
But parent StyleSheets are inherited by auxiliary dialogs! So they looks different depending on where they were launched from. It's weird.So now I should use auxiliary dialogs without parents because I'm concerned if parent has StyleSheet. So these dialogs always appears in the middle of the screen and I have additional entity in task bar on Windows for them.
How can I prevent such a StyleSheet inheritance?
To write something like "*{default view}" in child dialogs. Or "use only for this class" in parent dialogs. May be some attribute of dialog creation.
I can find absolutely no workaround! -
Hi
Stylesheets are cascading by nature. Any children will get the stylesheet.
So if you set it up on application ALL will have same look.If you wish to have some dialogs not having the look, make your stylesheet better using the specifier #
http://doc.qt.io/qt-5/stylesheet-examples.html
so if you use
QDialog {xxxx}
You can target add name
QDialog#Name {xxxx}
and only those with that name are affected.So the solution is to fix the style sheet so it ONLY targets the Dialogs you want.
There is no option to not make it cascading.
-
Thank you for the answer. But I don't undestandt yet how to use this syntax.
I have the following text in "styleSheet" field for my dialog object in QtDesigner:QToolButton{background-color: transparent; border-radius: 3; border: 1 solid transparent;}
QToolButton:disabled{color:#b0b0b0;}
QScrollBar {border: none;background: transparent;}I tried
QDialog#MyDialog
{
QToolButton{background-color: transparent; border-radius: 3; border: 1 solid transparent;}
QToolButton:disabled{color:#b0b0b0;}
QScrollBar {border: none;background: transparent;}
}
but it doesn't work. -
@Sofia
Its not the correct syntax/concept. :)
If you have another dialog where QToolButton should not be style, you need to
add names to that.
What you have shown is not valid. (sadly)QToolButton#name {background-color: transparent; border-radius: 3; border: 1 solid transparent;}
would be that.
So that is the issue ?
You have a "child" dialog of a dialog and ther you do not want
QToolButton styling to take effect? -
It's the issue, yes! It's a main subject of my complain :(
I have not only one QScrollBar and one QToolButton in my dialogs and their styleSheets.
There are, for example, QLabel and QEdit styling - font, padding, color for particular dialog and many labels and edits in it. And I don't want this styling in auxiliary dialogs. Should I enumerate all them with '#'?I have a lot of different working dialogs with different styles, but I want to have constant Message dialog everywhere.
I even can't have preview. I see one view in QtDesigner form and I see the absolutely different one in my program when this dialog is invoked from some parent window. -
Also
Why cant u just use names for dialog ?
So you list the names of the dialogs that should affect ?the text label in the middle is called nope
-
Alternatively, you can also create a common base class for the non styled
dialogs. StyleSheet allows for type/class specifier also.
So you could say only direct QDialogs.That way you can avoid specify names.
-
Thank you very much for your answers.
I read stylesheet-syntax.html doc several times before I wrote to this forum and several times after.
Could you please give an example for your last advice? What should I write for my child "Message" dialogs which now can have empty or non-empty styleSheets? -
Hi
I was thinking of this section
-
Thank you for details.
Actually parent dialog (not parent class, but parent widget from which child dialog is invoked) can have QLabels and QLabel-based modified widgets and child dialog also can have "pure" and modified QLabels.In any case the "summary" is - I always have to think specially and very thoroughly if some dialog can launch any child dialogs and if this dialog can be launched with parent.
All the same I see some logical error here...
-
@Sofia
Hi
You mean, its not full dialog you want to keep un-styled ?
But elements within?There is also
class MyPushButton : public QPushButton { // ... } // ... qApp->setStyleSheet("MyPushButton { background: yellow; }");
Where you use the subclass type.
Note, u can use , for a list
MyPushButton, X, YBut if you mean styled and un-styled is mixed , that wont help.
There is also option to use dynamic proprieties to flag stuff.
https://wiki.qt.io/Dynamic_Properties_and_Stylesheets