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

Use same StyleSheets in build and runtime



  • Hi Folks,

    I have a relative complex UI and I would like customize it by .css or .qss file. The problem is the following: How can I set a given .css file in the UI editor of the Qt Creator at any widgets styleSheet property and use this file at runtime as well?

    Regards,
    Norbert



  • The stylesheet property in the designer takes actual css, not a file name.

    @
    QFile styleSheet("myStyleSheet.css");
    if ( styleSheet.open( QFile::ReadOnly ) )
    {
    QTextStream textStream( &styleSheet );

        QString styleSheetContent = textStream.readAll();
    
        styleSheet.close();
        setStyleSheet(styleSheetContent);
    

    }
    @


Log in to reply