setStyleSheet sometimes not working
-
Thats interesting.
setStyleSheet("Data { font-size: 26pt; }");
or
setStyleSheet("#SMALL { font-size: 26pt; }");
does not work.
Neither doessetStyleSheet("{ font-size: 26pt; }");
But as you suggest
setStyleSheet("* { font-size: 26pt; }");
does.
Does that make any sense? -
@Jakob-Clausen
*
is the selector for "anything". This implies to me that none ofData#SMALL
,Data
or#SMALL
correctly address your widget instance, or maybe the right "bit" of it, but I do not know why. What is the ultimate base Qt type of yourData
class? -
It is derived from QLabel.
-
@Jakob-Clausen
setStyleSheet("QLabel { font-size: 26pt; }");
? -
That works! :-)
What does that mean? -
@Jakob-Clausen
One outside thought is: does yourData
class use theQ_OBJECT
macro in its definition? That is usually required for signals, I have no idea whether that just might be required for stylesheet-widget-inheritance to work, worth checking.Otherwise, produce the absolute minimum standalone program which creates a
QLabel
and showsetStyleSheet("QLabel { font-size: 26pt; }")
working, together with the minimum for a derivedMyLabel
and show thatsetStyleSheet("MyLabel { font-size: 26pt; }")
does not work.P.S.
YourData
class does not reside in a namespace, does it??P.P.S.
I don't know whether this applies to deriving fromQLabel
, but for deriving fromQWidget
read https://forum.qt.io/topic/55983/inheritance-from-qwidget-stylesheet-problem & https://stackoverflow.com/questions/7276330/qt-stylesheet-for-custom-widget. But I'm really thinking/pretty sure that applies toQWidget
only.... -
I use Q_OBJECT and it is not in a namespace.
I have also tried to reimplement the event callback without any luck.
Now I will try to create a minimal standalone example. -
Ok. I have not yet created the absolute minimum standalone program, but I have something else.
If I dosetStyleSheet("Data QLabel { font-size: 26pt; }")
then it works. :-)
But why? Isn't the stylesheet supposed to be passed along to children automatically? (I guess not).So Data#SMALL only applies to Data-objects with the name SMALL and not its descendants and Data QLabel applies to all QLabel descendants of Data.
Is what I just wrote correct? -
@Jakob-Clausen
But you said earlier thatData
is derived fromQLabel
(not e.g. that it contains aQLabel
)? That's why I asked? -
Ah.
Sorry about that.
It does both. -
But many thanks for your effort.
I appreciate it. -
@Jakob-Clausen said in setStyleSheet sometimes not working:
It does both.
It is a
QLabel
, and it also contains (another)QLabel
?P.S.
As a tip/suggestion, don't pickData
as a class name, and certainly not for some GUI element like labels. -
Yes.
In a layout.
Is that bad? -
@Jakob-Clausen said in setStyleSheet sometimes not working:
Is that bad?
[Nested
QLabel
s.] I don't know, I've never done it!