Maintaining Consistent Font Appearance in PySide6 QLabel: QSS vs. QFont
-
Hi,
Setting a stylesheet nukes the current style used to render the widget it's applied on hence you might see differences.
-
@SGaist said in Maintaining Consistent Font Appearance in PySide6 QLabel: QSS vs. QFont:
But as I wrote, two different styles are used, hence there can be difference.
I still don't understand. Maybe the OP will.
ISTM he is asking whether
label.setStyleSheet("""font:'SF Pro Display'; font-size:14pt; font-weight:900;""")
should be equated identically via
font = QFont('SF Pro Display', 14) font.setWeight(QFont.Weight.Black) # 900 label2.setFont(font)
Setting a stylesheet nukes the current style used to render the widget
Yes. But what current style was used for the
QLabel
in the above code? I don't see any? So I don't see setting the stylesheet has any style to nuke here? -
@JonB each platform has a default style to render the application. Setting a stylesheet triggers the replacement of the current style by the one that handles the stylesheet hence the "strange" look you get when changing elements such as buttons or QTabBar. It's more visible on platforms such as macOS or Windows.
-
@SGaist said in Maintaining Consistent Font Appearance in PySide6 QLabel: QSS vs. QFont:
each platform has a default style to render the application.
Ohhhh. Is this what I have seen about
Fusion
style and never understood? So that's some base CSS files forQLabel
s etc. to start with? I didn't know that, do you have the doc link which explains? Should be of interest to the OP. -
@JonB there's no CSS involved in the platform styles.
You can check the styles example.
KDAB has a very good article about dumping stylesheets in favor of custom styles.
-
@Emrecp
I believe @SGaist is telling you that you cannot guarantee that a widget with a stylesheet will look identical to one you construct with coded style attributes. As soon as you place a stylesheet on a widget you are (potentially) losing some styles which are inbuilt, so it may differ.I suggested earlier you remove the weight stuff in your example and see whether just with the font in "normal" it does or does not look identical using the same font in both code and stylesheet.
If you are coding inside
paintEvent()
then, as you say, you cannot use stylesheet. You can only set the attributes on aQFont
as you have done.I don't know whether you can go through the sources of Qt to discover just what a current style like Fusion does.
-