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. How to set a color scheme for a QMainWindow?
Forum Updated to NodeBB v4.3 + New Features

How to set a color scheme for a QMainWindow?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 301 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.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by
    #1

    In Qt 6.8.2 Desktop application that runs on Ubuntu 24.10, I have this main.cpp:

    #include "mainwindow.h"
    
    #include <QStyleHints>
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        QGuiApplication::styleHints()->setColorScheme(Qt::ColorScheme::Light);
    
        MainWindow w;
        w.show();
        return a.exec();
    }
    

    but this is the actual appearance:

    1d3959a0-6866-48aa-a212-3cbf382be595-image.png

    so it still follows the system theme regardless the explictly setting of the light color scheme.
    By the way if I write:

    QGuiApplication::styleHints()->setColorScheme(Qt::ColorScheme::Light);
    qDebug() << QGuiApplication::styleHints()->colorScheme();
    

    it outputs:

    Qt::ColorScheme::Dark

    It seems it silently ignores the request.
    Is there anything else I should add to force the desired color scheme?

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

      From a quick look at the code, the platform plugins currently don't handle that request yet.

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

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

        Hi,

        Which desktop environment are you using ?

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

        M 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Which desktop environment are you using ?

          M Offline
          M Offline
          Mark81
          wrote on last edited by
          #3

          @SGaist said in How to set a color scheme for a QMainWindow?:

          Which desktop environment are you using ?

          The default one that comes with Ubuntu 24.10:

          GNOME Shell 47.0

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

            From a quick look at the code, the platform plugins currently don't handle that request yet.

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

            M 1 Reply Last reply
            1
            • SGaistS SGaist

              From a quick look at the code, the platform plugins currently don't handle that request yet.

              M Offline
              M Offline
              Mark81
              wrote on last edited by Mark81
              #5

              @SGaist Got it. Out of curiosity, I RTFM but I wasn't able to find this information. Actually, the docs say:

              Sets the color scheme used by the application to an explicit scheme, or revert to the system's current color scheme if scheme is Qt::ColorScheme::Unknown.

              There is no mention that this function is not implemented yet.
              Are you saying there is no way to know this besides inspect the source code, aren't you?

              1 Reply Last reply
              0
              • M Mark81 has marked this topic as solved on
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #6

                I would expect to have somewhere a list of the platform where the value is in use. I haven't checked all the platform backends. Just the Linux ones where I haven't seen the value in use.

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

                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