3
votes

I have a child widget (QFrame) that has it's own style sheet setting. On this QFrame there are 4 labels that I do not want borders around. The parent widget to this QFrame is a QWidget and the border property is bleeding onto my QFrame labels.

I can make these go away with direct setting of the border for each label but I'd rather not have to do this. I just want to avoid the bleeddown. How do I do this?

BTW, both of these widgets (the parent and child) are created by a 3rd widget which is a QDialog. This QDialog created the parent, then the child, and passes the parent to the child in it's constructor.

1

1 Answers

0
votes

Have you tried more specific selectors? like selecting by object name, too? QLabel inherits QFrame. So when you tell your parent QFrame to behave a certain way, you are also telling all the QObjects that inherit QFrame, such as QLabel to also have the same style.

In the docs it mentions early on using setObjectName and #objectName.

If we want the property to apply only to one specific QLineEdit, we can give it a name using QObject::setObjectName() and use an ID Selector to refer to it:

myDialog->setStyleSheet("QLineEdit#nameEdit { background-color: yellow }");

http://doc.qt.io/qt-5/stylesheet-examples.html

Later it has more examples of selectors:

http://doc.qt.io/qt-5/stylesheet-examples.html#complex-selector-example

And like you already mentioned in your answer, an alternative would be to have a different style written out for your QLabels.

The selectors in Qt StyleSheets behave with surprising similarity to what they do in CSS. Ordering, additional selectors, etc, can get you to be very specific about which item(s) you are wanting a style to apply to.

Hope that helps.