is it possible to turn off stylesheet distribution?
-
Hi,
my html-knowledge is quite outdated, but if I remember well, a toplevel stylesheet did not overwrite a style-property used at a div, or whatever element (of cause without selectors).
Maybe that changed - don't know.
... any way: I won't change Qt. This project is a challenge for me, so I just use it and I have to live with the quirks and issues.
I am spoiled by java, which has solved many things much more elegantly than Qt. I can't remember, that I ever had such shocking impressions than with using Qt, where I already had some.
-
Hi,
my html-knowledge is quite outdated, but if I remember well, a toplevel stylesheet did not overwrite a style-property used at a div, or whatever element (of cause without selectors).
Maybe that changed - don't know.
... any way: I won't change Qt. This project is a challenge for me, so I just use it and I have to live with the quirks and issues.
I am spoiled by java, which has solved many things much more elegantly than Qt. I can't remember, that I ever had such shocking impressions than with using Qt, where I already had some.
@django-Reinhard said in is it possible to turn off stylesheet distribution?:
but if I remember well, a toplevel stylesheet did not overwrite a style-property used at a div, or whatever element (of cause without selectors).
Maybe that changed - don't know.Your desktop application is not a web page. This is Qt Style Sheets, or QSS. It has some similarities to CSS but it is not CSS.
Yo, I got that by now. The point is that no widget has an objectName by default.
If you are using Qt Designer standalone or embedded in Qt Creator then every widget object gets an object name by default. It matches the name you see in the form object tree (and you can change those). Here is the code generated by uic for a simple combo box I dropped in the form.
comboBox = new QComboBox(Form); comboBox->setObjectName(QString::fromUtf8("comboBox"));If you are hand coding the forms then you can set a object name if you want, or need, to so that QSS has a target you can use.
-
Hi,
my html-knowledge is quite outdated, but if I remember well, a toplevel stylesheet did not overwrite a style-property used at a div, or whatever element (of cause without selectors).
Maybe that changed - don't know.
... any way: I won't change Qt. This project is a challenge for me, so I just use it and I have to live with the quirks and issues.
I am spoiled by java, which has solved many things much more elegantly than Qt. I can't remember, that I ever had such shocking impressions than with using Qt, where I already had some.
@django-Reinhard said in is it possible to turn off stylesheet distribution?:
my html-knowledge is quite outdated, but if I remember well, a toplevel stylesheet did not overwrite a style-property used at a div, or whatever element (of cause without selectors).
Maybe that changed - don't know.Sure it does.
<html> <body> <div style="color:red;"> I'm red. <div>I'm red too, 'cos my parent is red.</div> <div style="color:blue;">I'm blue, 'cos I don't want to be like my parent.</div> </div> </body> </html>Widgets are analogous to the "div"s here.
I just use it and I have to live with the quirks and issues.
I am spoiled by java, which has solved many things much more elegantly than Qt. I can't remember, that I ever had such shocking impressions than with using Qt, where I already had some.
Although @ChrisW67 is right that QSS is not CSS, Qt's style inheritance rules are fully consistent with CSS here. And CSS is used for websites all around the world, so it really shouldn't be so shocking.
-
@JKSH said in is it possible to turn off stylesheet distribution?:
Widgets are analogous to the "div"s here.
Well, from what I tested, they are not.
Your sample with the divs is what I believed in.
But Qt behave different.First I set background color to FixtureManager, which is the notebook-page. Messagebox, child-editors and QLineEdits are all children of FixtureManager - so all changed to green.
Then I set background-color of QLineEdit to white, but they stayed green. I tried to change autofillBackground, but it made no difference.
Then I tried the same for the child editor. But setting backgroundcolor was not taken into account. All stayed green.
That was the reason why I was shocked!The div sample is ok and if Qt would behave the same, everything would be fine.
-
@JKSH said in is it possible to turn off stylesheet distribution?:
Widgets are analogous to the "div"s here.
Well, from what I tested, they are not.
Your sample with the divs is what I believed in.
But Qt behave different.First I set background color to FixtureManager, which is the notebook-page. Messagebox, child-editors and QLineEdits are all children of FixtureManager - so all changed to green.
Then I set background-color of QLineEdit to white, but they stayed green. I tried to change autofillBackground, but it made no difference.
Then I tried the same for the child editor. But setting backgroundcolor was not taken into account. All stayed green.
That was the reason why I was shocked!The div sample is ok and if Qt would behave the same, everything would be fine.
-
@JKSH said in is it possible to turn off stylesheet distribution?:
Widgets are analogous to the "div"s here.
Well, from what I tested, they are not.
Your sample with the divs is what I believed in.
But Qt behave different.First I set background color to FixtureManager, which is the notebook-page. Messagebox, child-editors and QLineEdits are all children of FixtureManager - so all changed to green.
Then I set background-color of QLineEdit to white, but they stayed green. I tried to change autofillBackground, but it made no difference.
Then I tried the same for the child editor. But setting backgroundcolor was not taken into account. All stayed green.
That was the reason why I was shocked!The div sample is ok and if Qt would behave the same, everything would be fine.
@django-Reinhard said in is it possible to turn off stylesheet distribution?:
The div sample is ok and if Qt would behave the same, everything would be fine.
Everything is fine then:
auto topLevel = new QWidget; auto layout = new QVBoxLayout; auto greenChild = new QLineEdit("Green like parent", topLevel); auto whiteChild = new QLineEdit("White like a boss", topLevel); topLevel->setStyleSheet("background-color: green;"); whiteChild->setStyleSheet("background-color: white;"); layout->addWidget(greenChild); layout->addWidget(whiteChild); topLevel->setLayout(layout); topLevel->show();Tested on Qt 5.15.2, MinGW 64-bit.
@Bonnie said in Weird stylesheet behavior for ui form designer:
The styleSheet you set on a widget will also apply to all his children.
What a stupid feature :(
Bonnie was talking about how
greenChildinherits the green background from its parent.As you can see,
whiteChildcan definitely be white, even if its parent is green. -
@django-Reinhard
Then maybe your code is wrong, we can't see it. More specific rules should override more generic rules in QSS, like in CSS.@JonB said in is it possible to turn off stylesheet distribution?:
Then maybe your code is wrong
Well, that may be true.
I'm not that fit with Qt that I could state, that I don't make errors.
I tested it with different widgets at different "distance" from parent and I got always the same result - every thing was green.So if it was my fault, I beg your pardon.
-
@JonB said in is it possible to turn off stylesheet distribution?:
Then maybe your code is wrong
Well, that may be true.
I'm not that fit with Qt that I could state, that I don't make errors.
I tested it with different widgets at different "distance" from parent and I got always the same result - every thing was green.So if it was my fault, I beg your pardon.
-
Hi,
never mind!
I'll learn the Qt-way of coding and it wasn't my last error ;)
-
Hi,
never mind!
I'll learn the Qt-way of coding and it wasn't my last error ;)
@django-Reinhard said in is it possible to turn off stylesheet distribution?:
I'll learn the Qt-way of coding
Did you try the code in my last message?