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. Dark mode doesn't work well in Qt 6.5
QtWS25 Last Chance

Dark mode doesn't work well in Qt 6.5

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 5 Posters 2.5k Views
  • 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.
  • Pl45m4P Pl45m4

    @lincoln said in Dark mode doesn't work well in Qt 6.5:

    only changes if another operation is done, my question is how can I make the title bar of the form also change color, along with the entire app, thanks in advance.

    What "other operation"? [Edit: Haven't seen the text below]

    such as changing the window or resizing

    I assume it's because you need a full repaint/render of your window to change the title bar. The button might only refresh the widget's content.

    lincolnL Offline
    lincolnL Offline
    lincoln
    wrote on last edited by
    #5

    @Pl45m4 Could you show me some example or code of how to do it please.

    Solitary wolf

    Pl45m4P 1 Reply Last reply
    0
    • lincolnL lincoln

      @raoufM I made the change you said but it doesn't work, now I don't go back to light mode anymore.

      R Offline
      R Offline
      raoufM
      wrote on last edited by
      #6

      @lincoln said in Dark mode doesn't work well in Qt 6.5:

      I made the change you said but it doesn't work, now I don't go back to light mode anymore.

      I apologize for the confusion. I made a mistake in my previous response. Instead of QApplication::setPalette, you should use QWidget::setPalette to set the palette for your main widget. QApplication::setPalette sets the palette for the entire application, including windows and dialogs, whereas QWidget::setPalette sets the palette only for the widget that you call it on.

      try it now it should be executable :

      Widget::Widget(QWidget *parent)
      : QWidget(parent), ui(new Ui::Widget), standardPalette{qApp->palette()}
      {
      ui->setupUi(this);

      QObject::connect(ui->pushButton, &QPushButton::clicked, this, &{
      qApp->setPalette(standardPalette);
      });

      QObject::connect(ui->pushButton_2, &QPushButton::clicked, this, &{
      QPalette darkPalette;

      darkPalette.setColor(QPalette::Window, QColor(53, 53, 53));
      darkPalette.setColor(QPalette::WindowText, Qt::white);
      darkPalette.setColor(QPalette::Base, QColor(25, 25, 25));
      darkPalette.setColor(QPalette::AlternateBase, QColor(53, 53, 53));
      darkPalette.setColor(QPalette::ToolTipBase, QColor(53, 53, 53));
      darkPalette.setColor(QPalette::ToolTipText, Qt::white);
      darkPalette.setColor(QPalette::Text, Qt::white);
      darkPalette.setColor(QPalette::PlaceholderText,QColor(127,127,127));
      darkPalette.setColor(QPalette::Button, QColor(53, 53, 53));
      darkPalette.setColor(QPalette::ButtonText, Qt::white);
      darkPalette.setColor(QPalette::BrightText, Qt::red);
      darkPalette.setColor(QPalette::Link, QColor(42, 130, 218));
      darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218));
      darkPalette.setColor(QPalette::HighlightedText, Qt::black);
      darkPalette.setColor(QPalette::Disabled, QPalette::Text, QColor(164, 166, 168));
      darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, QColor(164, 166, 168));
      darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(164, 166, 168));
      darkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(164, 166, 168));
      darkPalette.setColor(QPalette::Disabled, QPalette::Base, QColor(68, 68, 68));
      darkPalette.setColor(QPalette::Disabled, QPalette::Window, QColor(68, 68, 68));
      darkPalette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(68, 68, 68));
      
      this->setPalette(darkPalette);
      qApp->setStyle("Fusion");
      

      });
      }

      Widget::~Widget()
      {
      delete ui;
      }

      lincolnL 1 Reply Last reply
      0
      • lincolnL lincoln

        @Pl45m4 Could you show me some example or code of how to do it please.

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by
        #7

        @lincoln said in Dark mode doesn't work well in Qt 6.5:

        Could you show me some example or code of how to do it please.

        Try a call of update() or repaint() on your window/widget.

        // at the end of your lambda
        this->update();
        

        Or even do what is explained here.
        But: use it with care. Depending on your app / app design, "just" updating all windows/widgets at once can be a very resource consuming task. Esp. when calling it frequently.

        • https://doc.qt.io/qt-6/qapplication.html#allWidgets

        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        lincolnL 1 Reply Last reply
        0
        • Pl45m4P Pl45m4

          @lincoln said in Dark mode doesn't work well in Qt 6.5:

          Could you show me some example or code of how to do it please.

          Try a call of update() or repaint() on your window/widget.

          // at the end of your lambda
          this->update();
          

          Or even do what is explained here.
          But: use it with care. Depending on your app / app design, "just" updating all windows/widgets at once can be a very resource consuming task. Esp. when calling it frequently.

          • https://doc.qt.io/qt-6/qapplication.html#allWidgets
          lincolnL Offline
          lincolnL Offline
          lincoln
          wrote on last edited by
          #8

          @Pl45m4 I already tried update() and repaint(), and nothing happens, anyway thanks for your answer.

          Solitary wolf

          1 Reply Last reply
          0
          • R raoufM

            @lincoln said in Dark mode doesn't work well in Qt 6.5:

            I made the change you said but it doesn't work, now I don't go back to light mode anymore.

            I apologize for the confusion. I made a mistake in my previous response. Instead of QApplication::setPalette, you should use QWidget::setPalette to set the palette for your main widget. QApplication::setPalette sets the palette for the entire application, including windows and dialogs, whereas QWidget::setPalette sets the palette only for the widget that you call it on.

            try it now it should be executable :

            Widget::Widget(QWidget *parent)
            : QWidget(parent), ui(new Ui::Widget), standardPalette{qApp->palette()}
            {
            ui->setupUi(this);

            QObject::connect(ui->pushButton, &QPushButton::clicked, this, &{
            qApp->setPalette(standardPalette);
            });

            QObject::connect(ui->pushButton_2, &QPushButton::clicked, this, &{
            QPalette darkPalette;

            darkPalette.setColor(QPalette::Window, QColor(53, 53, 53));
            darkPalette.setColor(QPalette::WindowText, Qt::white);
            darkPalette.setColor(QPalette::Base, QColor(25, 25, 25));
            darkPalette.setColor(QPalette::AlternateBase, QColor(53, 53, 53));
            darkPalette.setColor(QPalette::ToolTipBase, QColor(53, 53, 53));
            darkPalette.setColor(QPalette::ToolTipText, Qt::white);
            darkPalette.setColor(QPalette::Text, Qt::white);
            darkPalette.setColor(QPalette::PlaceholderText,QColor(127,127,127));
            darkPalette.setColor(QPalette::Button, QColor(53, 53, 53));
            darkPalette.setColor(QPalette::ButtonText, Qt::white);
            darkPalette.setColor(QPalette::BrightText, Qt::red);
            darkPalette.setColor(QPalette::Link, QColor(42, 130, 218));
            darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218));
            darkPalette.setColor(QPalette::HighlightedText, Qt::black);
            darkPalette.setColor(QPalette::Disabled, QPalette::Text, QColor(164, 166, 168));
            darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, QColor(164, 166, 168));
            darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(164, 166, 168));
            darkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(164, 166, 168));
            darkPalette.setColor(QPalette::Disabled, QPalette::Base, QColor(68, 68, 68));
            darkPalette.setColor(QPalette::Disabled, QPalette::Window, QColor(68, 68, 68));
            darkPalette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(68, 68, 68));
            
            this->setPalette(darkPalette);
            qApp->setStyle("Fusion");
            

            });
            }

            Widget::~Widget()
            {
            delete ui;
            }

            lincolnL Offline
            lincolnL Offline
            lincoln
            wrote on last edited by
            #9

            @raoufM It remains the same, the title bar does not change, well thanks for your answer.

            Solitary wolf

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SimonSchroeder
              wrote on last edited by
              #10

              A widget is only the underlying Qt representation without the window decoration (at least on some platforms). Try to get the underlying window first and update the window instead of just the widget.

              lincolnL 1 Reply Last reply
              1
              • S SimonSchroeder

                A widget is only the underlying Qt representation without the window decoration (at least on some platforms). Try to get the underlying window first and update the window instead of just the widget.

                lincolnL Offline
                lincolnL Offline
                lincoln
                wrote on last edited by
                #11

                @SimonSchroeder
                Well, I don't understand what you mean by underlying window, and I have no idea how to do it, but thanks for your answer.

                Solitary wolf

                S 1 Reply Last reply
                0
                • C Offline
                  C Offline
                  CPPUIX
                  wrote on last edited by
                  #12

                  See this for more information about what @SimonSchroeder mentioned.

                  1 Reply Last reply
                  0
                  • lincolnL lincoln

                    @SimonSchroeder
                    Well, I don't understand what you mean by underlying window, and I have no idea how to do it, but thanks for your answer.

                    S Offline
                    S Offline
                    SimonSchroeder
                    wrote on last edited by
                    #13

                    @lincoln said in Dark mode doesn't work well in Qt 6.5:

                    Well, I don't understand what you mean by underlying window, and I have no idea how to do it, but thanks for your answer.

                    Qt has both QWidget and QWindow. The underlying operating system only knows about windows. However, creating each button, etc. as a window through the OS would be very slow. That is why Qt has a soft layer on top to quickly generate widgets instead of OS windows. The top level widgets still need to be windows.

                    Use https://doc.qt.io/qt-6/qwidget.html#windowHandle to get the underlying window if available. There, you can call requestUpdate().

                    lincolnL 1 Reply Last reply
                    0
                    • S SimonSchroeder

                      @lincoln said in Dark mode doesn't work well in Qt 6.5:

                      Well, I don't understand what you mean by underlying window, and I have no idea how to do it, but thanks for your answer.

                      Qt has both QWidget and QWindow. The underlying operating system only knows about windows. However, creating each button, etc. as a window through the OS would be very slow. That is why Qt has a soft layer on top to quickly generate widgets instead of OS windows. The top level widgets still need to be windows.

                      Use https://doc.qt.io/qt-6/qwidget.html#windowHandle to get the underlying window if available. There, you can call requestUpdate().

                      lincolnL Offline
                      lincolnL Offline
                      lincoln
                      wrote on last edited by
                      #14

                      @SimonSchroeder Hello friend, I tried to do what you mention, but when querying this->windowHandle();
                      the result is always a nullptr.

                      Solitary wolf

                      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