Some styles not applied to custom widget
-
Hi all,
I have a custom widget publicly derived from QFrame.
This custom widget has three QLabels within it so the rusultant structure looks like this:
I am trying to set the color of the text in these labels using QSS stylesheet.
I find that I can successfully set font size, font family, padding and background colour but cannot seem to find any way of setting the text colour.QLabelledInfoBox#MyNamedObject QLabel { font: 10pt "Arial"; background-color: rgb(255, 0, 0); padding:10px 40px 10px 40px; color: rgb(0, 255, 0); }
I know I am getting the selectors right because the font, padding and background colours are all changed as the style dictates.
It's probably something blindingly obvious, but I can't seem to be able to set the colour of the text.
TIA
Tony -
@Anthony-Steer said in Some styles not applied to custom widget:
QLabelledInfoBox#MyNamedObject QLabel { font: 10pt "Arial"; background-color: rgb(255, 0, 0); padding:10px 40px 10px 40px; color: rgb(0, 255, 0); }
- What happens if, instead of using a selector on a global stylesheet, you apply this stylesheet to a specific instance of a QLabel in your QLabelledInfoBox? (e.g. in your constructor, call
InfoData->setStyleSheet(...);
) - Do you have any other stylesheets that apply to QLabels? If so, what happens if you disable those?
- What happens if, instead of using a selector on a global stylesheet, you apply this stylesheet to a specific instance of a QLabel in your QLabelledInfoBox? (e.g. in your constructor, call
-
@JKSH said in Some styles not applied to custom widget:
color: rgb(0, 255, 0);
Hi,
thank you for prompting debugging in this area. (I had already tried emptying the global style sheet bar this one - it had no effect)
Also, setting the style in the constructor of my class worked as avertised.Anyway, what I have dicovered (which was a big surprise), is that removing the style applied in the designer (and also my temporary constructor style) allowed my global Qss sheet to have an effect. Putting either of them back in stopped the global sheet working. I have confirmed that the global style sheet is being applied after the construction of my objects.
I guess I have a workaround for now, but it is not ideal because these classes are used in other projects withthe default colours. It will mean having to revisit those projects and add a stlye sheet entry for the defaults. Any further light you can shed on the subject would be most appreciated.
-
@Anthony-Steer said in Some styles not applied to custom widget:
I guess I have a workaround for now, but it is not ideal because these classes are used in other projects withthe default colours. It will mean having to revisit those projects and add a stlye sheet entry for the defaults. Any further light you can shed on the subject would be most appreciated.
I'm glad to hear you have a way forward, even if it's not ideal.
I don't have any clues as to why this behaviour occurs, I'm afraid.
-
@Anthony-Steer this is actually a known bug for older versions of qt.
What version of Qt are you using? My guess if 5.9.x or lower 5.12.x ? -
@J-Hilk said in Some styles not applied to custom widget:
@Anthony-Steer this is actually a known bug for older versions of qt.
Ooh, got a link to the report?
-
@JKSH said in Some styles not applied to custom widget:
@J-Hilk said in Some styles not applied to custom widget:
@Anthony-Steer this is actually a known bug for older versions of qt.
Ooh, got a link to the report?
that took way longer to find than I would like too admit:
https://bugreports.qt.io/browse/QTBUG-77006 -
@J-Hilk said in Some styles not applied to custom widget:
that took way longer to find than I would like too admit:
https://bugreports.qt.io/browse/QTBUG-77006C'mon, 4 minutes is great!
-
@Anthony-Steer when you check the bug report I linked, you'll see that 5.13 is also listed under the effected version!
So, it's probably it.