Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt Style Sheets versus setFont function.



  • Is there any particular reason why the docs for Qt 5.X discourage the intermingling of Style Sheets with the use of the QApplication::setFont function?

    Under the definition of QApplication::setFont the doc states: "Warning: Do not use this function in conjunction with Qt Style Sheets. The font of an application can be customized using the "font" style sheet property. To set a bold font for all QPushButtons, set the application styleSheet() as "QPushButton { font: bold }".

    I would like to know why such usage is discouraged. If it is for convention I may ignore it, but if it is dangerous I may heed it.

    Thanks in advance to anyone who answers.


  • Lifetime Qt Champion

    Hi
    I think It's mostly due to it might not work as expected.
    The SetFont promise to change the font used by any widget in the application but

    if you apply a style sheet to any of the widgets then stylesheet win and calling
    QApplication::setFont seems to have no effect.

    So if you have an applicationwide stylesheet that sets the fonts and combined it with
    QApplication::setFont then the effect is not as expected reading the docs.

    In any case, it does not seem dangerous as I did use it to set a larger font for touch and at the same
    time had stylesheet to tweak the look of several widgets.



  • @mrjj Thank you so much. This takes some worry off my mind.


Log in to reply