Search code examples
c++qtqtstylesheets

QFont to qss stylesheet


With a QFontDialog I get a QFont object as return value. I am using Qt stylesheets with widgets, so setting myWidget->setFont(fontFromDialog) does not seem to have any effect.

Can I translate a font object into a qss string representing the values of the font, similar to font.toString() used with the settings.


Solution

  • You can set the font straight from the dialog using getFont, i'd try this potentially, might have to alter some code.

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

    Also, have a look at the Qt documentation for this as it could potentially help a lot!