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. Switching Styles at runtime?
Forum Updated to NodeBB v4.3 + New Features

Switching Styles at runtime?

Scheduled Pinned Locked Moved Solved General and Desktop
3 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.
  • BDC_PatrickB Offline
    BDC_PatrickB Offline
    BDC_Patrick
    wrote on last edited by
    #1

    Hi there..

    I managed to switch the Style of my Application in the main.cpp, with

        if(CurrentTheme == "dark"){
            // Load the dark application style
            QFile styleFile(":/style/style/TGS_Dark.qss");
            styleFile.open( QFile::ReadOnly );
            // Apply the loaded stylesheet
            QString style( styleFile.readAll() );
            a.setStyleSheet(style);
        }else{
            // Set default fusion style
            QApplication::setStyle(QStyleFactory::create("Fusion"));
        }
    

    Now, i want to change the Theme of the Window, when the MainWindow is opened, by having the User being able to Select a Theme from a ComboBox (currently holding the Items "dark" and "light")

    I can change the Style to the dark theme with:

        if(CurrentTheme == "dark"){
            // Load the dark application style
            QFile styleFile(":/style/style/TGS_Dark.qss");
            styleFile.open( QFile::ReadOnly );
            // Apply the loaded stylesheet
            QString styledark( styleFile.readAll() );
            qApp->setStyleSheet(styledark);
        }else{
            // Set default fusion style ?
        }
    

    But i can´t simply copy the Code for the fusion theme over here..
    How can i switch back to fusion, like for the dark Style?

    1 Reply Last reply
    0
    • SGaistS SGaist

      Hi,

      You can do the same or even use the string version.

      See this example.

      BDC_PatrickB Offline
      BDC_PatrickB Offline
      BDC_Patrick
      wrote on last edited by
      #3

      @SGaist Not with my past method..

      My current method involves a Change of the Palette of fusion, to get dark mode.. and simply switch palettes from lightPalette to darkPalette.

      New problem following...

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        You can do the same or even use the string version.

        See this example.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        BDC_PatrickB 1 Reply Last reply
        2
        • SGaistS SGaist

          Hi,

          You can do the same or even use the string version.

          See this example.

          BDC_PatrickB Offline
          BDC_PatrickB Offline
          BDC_Patrick
          wrote on last edited by
          #3

          @SGaist Not with my past method..

          My current method involves a Change of the Palette of fusion, to get dark mode.. and simply switch palettes from lightPalette to darkPalette.

          New problem following...

          1 Reply Last reply
          1

          • Login

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