简体   繁体   English

QFont到QSS样式表

[英]QFont to qss stylesheet

With a QFontDialog I get a QFont object as return value. 使用QFontDialog我得到一个QFont对象作为返回值。 I am using Qt stylesheets with widgets, so setting myWidget->setFont(fontFromDialog) does not seem to have any effect. 我使用Qt样式表与窗口小部件,所以设置myWidget->setFont(fontFromDialog)似乎没有任何效果。

Can I translate a font object into a qss string representing the values of the font, similar to font.toString() used with the settings. 我可以将字体对象转换为代表字体值的font.toString()字符串,类似于与设置一起使用的font.toString()

You can set the font straight from the dialog using getFont, i'd try this potentially, might have to alter some code. 您可以使用getFont从对话框直接设置字体,我可能会尝试这样做,可能必须更改一些代码。

myWidget.setFont(QFontDialog::getFont(0, myWidget.font()));

Also, have a look at the Qt documentation for this as it could potentially help a lot! 另外,请查看Qt文档,因为它可能会很有帮助!

Try this: 尝试这个:

QFont aFont;
QString theStyleSheet = QString("font: 75 %1pt \"%2\"").arg(aFont.pointSize()).arg(aFont.family());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM