Reputation: 1002
To keep a Stylesheet dynamic regarding DPI settings, I want to set certain parts of it from code.
This works:
my_label->setStyleSheet( QString( "font-size: 30px;" ) );
Yet, this doesn't:
my_label->setStyleSheet( QString( "font-size: %1px;" ).arg( 30 ) );
Can anyone enlighten me, why this is? Running Qt 5.7.
Upvotes: 0
Views: 1915
Reputation: 1002
The issue was a combination of two things:
While I did try different combinations (integer values (30), converting to QString first), I did not try using an integer value AND converting it to QString together. So everyone was kinda right. Thanks for the patience.
Upvotes: 2
Reputation: 4050
Conver the number to a string, QString::number:
my_label->setStyleSheet(QString("QLabel{font-size: %1 px;}").arg(QString::number(30));
Or try it by using QFont, use this generic function for this purpose:
void updateFontSize(QLabel* label, int fontSize) {
QFont font = label->font();
if (font.pointSize() != fontSize) {
font.setPointSize(fontSize);
label->setFont(font);
}
}
Upvotes: -1