Convert QFont styleName to stylesheet
-
Hello, guys! I need some help.
Imagine, I have a widget form and display values on it, and I want the values' labels to be displayed with some other font than the other text labels. So I give them a css class name for example "Value" and want to set some font through the stylesheet (QLabel.Value {...}).
I try to set up QLabel's font through the Qt Designers stylesheet dialog, but if I select for example font Lato with style Medium, Designer converts it to string:font: 57 12pt "Lato";
and the label shows very thin font which is absolutely not Medium style.
If I try another font Gotham with style Book, the Designer doesn't see it at all and outputs:
font: 12pt "Gotham".
So the questions are:
- Do stylesheets support font style names?
- If no, which qt way I can assign required font to all of the labels (or widgets) of the same type?
P.S. I'm using Windows 10, Qt 15.2 MinGW.
-
https://doc.qt.io/qt-5/qfont.html#Style-enum
QFont::Weight ==> font.setWeight( Qt::Medium )
QFont font( QString( "Lato" ), 12 );
font.setWeight( Qt::Medium );True: can not find style book
-
https://doc.qt.io/qt-5/qfont.html#Style-enum
QFont::Weight ==> font.setWeight( Qt::Medium )
QFont font( QString( "Lato" ), 12 );
font.setWeight( Qt::Medium );True: can not find style book
@JoeCFD First of all, this way you set font through the API, but I need to set one through the stylesheet cause I need font to be set to the whole class of widgets.
BTW, style name have to be set by function setStyleName, for example:font.setStyleName("Book");
and it works ok.
-
@JoeCFD First of all, this way you set font through the API, but I need to set one through the stylesheet cause I need font to be set to the whole class of widgets.
BTW, style name have to be set by function setStyleName, for example:font.setStyleName("Book");
and it works ok.
@AlexNevskiy Is not it same to set font to their parent widget?
-
@AlexNevskiy Is not it same to set font to their parent widget?
@JoeCFD If I set font to the parent widget it will apply to all the child widgets and not to the certain class of widgets.
-
@JoeCFD If I set font to the parent widget it will apply to all the child widgets and not to the certain class of widgets.
@AlexNevskiy It is true. And it is the same with stylesheet.