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

[Solved] Dynamically set style.



  • Hi all,

    I'm trying to dynamically set application style in a following way:

        QApplication::setStyle(QStyleFactory::create(styleName));
        QApplication::setPalette(this->style()->standardPalette());
    

    where styleName can be one of QStyleFactory::keys();
    Every time above is executed look of the application changes but not correctly. To complete application must be restarted.

    Is there a way how to avoid restarting?

    Thanks,
    Tomas



  • OK, I found a solution.
    Two methods have to be called in reverse order.

        QStyle *style = QStyleFactory::create(styleName);
        QApplication::setPalette(style->standardPalette());
        QApplication::setStyle(style);
    

    And now it works as desired.

    Tomas