Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Changing stylesheet in runtime
Qt 6.11 is out! See what's new in the release blog

Changing stylesheet in runtime

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mit_cruzeM Offline
    mit_cruzeM Offline
    mit_cruze
    wrote on last edited by
    #1
    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 (data.open(QFile::ReadOnly))
            {
                QTextStream styleIn(&data);
                style = styleIn.readAll();
                data.close();
                app.setStyleSheet(style);
                bStyleIt = true;
            }
        }
        MainWindow w;
        w.setFixedSize(500,350);
        w.showMaximized();
        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?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      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

      #MyDialog{
      // style for dialog
      }
      

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • mit_cruzeM Offline
        mit_cruzeM Offline
        mit_cruze
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

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

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved