Force light mode on system set to dark mode
-
Hi folks,
I generally keep my computer in dark mode,
but there is one Qt app where there is a QTextEdit
and I really need it (alone) to be in light mode.
Is there a way to set the light theme for only 1 widget?
I tried setting the style sheet but there are many
colors in use, and I find that the QTextEdit is
automatically switching many other them to
dark mode equivalents. I'm using C++.
Thanks. -
-
@Axel-Spoerl How can I determine the default palette for Light Mode?
-
@clarify
It depends on the platform theme, how the standard palette for a light color scheme looks like. It differs by OS. On Linux, it also depends on the theming applied to Gnome or KDE.If you are building for a specific platform setup, I'd probably start by switching to light mode, and dumping a default constructed palette:
qDebug() << QPalette()
. I'd use the output to hard code my own light-enforced palette.If the application is cross-platform, you can blend that palette by dumping it on each platform and making the light-enforced palette platform-dependent. Alternatively, you could use the fusion palette. I'd consider that as the best possible compromise for a uniform, cross-platform palette.
See methodqt_fusionPalette()
insrc/gui/kernel/qplatformtheme.cpp
. -
@Axel-Spoerl said in Force light mode on system set to dark mode:
qDebug() << QPalette()
FYI The expression "qDebug() << QPalette()" only produces errors.
I'm surprised there isn't a simple way to set a widget to light or dark mode, even if the colors originate from the system. -
@clarify said in Force light mode on system set to dark mode:
@Axel-Spoerl said in Force light mode on system set to dark mode:
qDebug() << QPalette()
FYI The expression "qDebug() << QPalette()" only produces errors.
Please share those errors.
I'm surprised there isn't a simple way to set a widget to light or dark mode, even if the colors originate from the system.
Understand your point. The color scheme is just implemented on a system level by principle. Exceptions are difficult to generalize: what’s the default behavior? If the system scheme changes after having been overridden on a single widget, what should happen with that widget? Ignore the system change? Bounce back to the system scheme? Invert?
All options are available, they just have to be implemented locally.
-
@Axel-Spoerl said in Force light mode on system set to dark mode:
Please share those errors.
I'm not sure what went wrong before. This time it worked and it printed this:
QPalette(resolve=0x0,)
Exceptions are difficult to generalize: what’s the default behavior?
In dark mode, the QTextEdit has a black or near-black background, and text that would have been black is white.
-
In Qt 6.5, a platform-specific option has been introduced to control dark mode behavior (https://doc.qt.io/qt-6/qguiapplication.html#platform-specific-arguments) . We can now customize how the Qt application responds to dark color schemes on the Windows 11 desktop. To enable or disable dark mode, set the environment variable QT_QPA_PLATFORM with the desired value before declaring your QApplication instance.