Important: Please read the Qt Code of Conduct -

Changing stylesheet in runtime

  • int main(int argc, char *argv[])
        QApplication app(argc, argv);
        // Q_INIT_RESOURCE(dockwidgets);
        // w.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
        bool bStyleIt = false;
            QFile data("/home/einfochips/BEL_VMS_CLIENT/stylesheet.qss");
            QString style;
            if (
                QTextStream styleIn(&data);
                style = styleIn.readAll();
                bStyleIt = true;
        MainWindow w;
        return app.exec();

    Hello this is my main.cpp of application where I want to set different themes. QFile data("/home/einfochips/BEL_VMS_CLIENT/stylesheet.qss"); This line reads stylesheet file and applies once I run application.
    But I have another dialog with name theme.cpp where I have 3 radiobuttons which have some colors. So my question is how to apply stylesheeet to qAPP runtime?

  • You can apply stylesheets to individual widgets or set the call setObjectName("MyDialog") in the dialog you want to look differently and include a section on the sylesheet dedicated to it

    // style for dialog

  • I want to make change to all my dialogs and mainwindow too.

  • ok, I lost you then. could you post the content of /home/einfochips/BEL_VMS_CLIENT/stylesheet.qss and what you want to achieve?

Log in to reply