Windows: better handling of darkmode support

43ef22045c6f4fbf76d5cfa4ca32160d919b9984 turned dark mode support on for
both styling and window frames. However, the default palette and style
support in Qt is too incomplete, resulting in unreadable UIs when using
certain styles (e.g. fusion). Also the vista style is not supporting
dark mode.

If we don't turn on dark style support, then dark frame support doesn't
look good either. However, many application developers have implement a
dark theme themselves, and we should have a dark frame for those
applications.

So partially revert 43ef22045c6f4fbf76d5cfa4ca32160d919b9984 so that
dark style support is disabled by default, and leave dark frame support
on. However, only activate dark frames if the palette is dark, i.e. if
the window background color in the default palette is darker than the
text color (or if DarkModeStyle is explicitly turned on by running the
application with -platform windows:darkmode=2).

This way, dark-themed applications get a dark frame on dark Windows, and
a light frame on light Windows; and light-themed applications (including
default Qt applications) get a light frame all the time.

Fixes: QTBUG-72028
Change-Id: I61f1b1e43b2a4ba69848d5d8bec921c0790fe511
Reviewed-by: Marius Kittler <mariuskittler@gmx.de>
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
(cherry picked from commit 5ea7e3a8111b2939f0c91b750aa1c62ab16ab715)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Volker Hilsheimer 2022-07-14 17:00:16 +02:00 committed by Qt Cherry-pick Bot
parent 85077365c0
commit bc3e6af3ce
3 changed files with 14 additions and 7 deletions

View File

@ -1101,14 +1101,14 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message,
if (darkMode != QWindowsContextPrivate::m_darkMode) {
QWindowsContextPrivate::m_darkMode = darkMode;
auto integration = QWindowsIntegration::instance();
if (integration->darkModeHandling().testFlag(QWindowsApplication::DarkModeWindowFrames)) {
for (QWindowsWindow *w : d->m_windows)
w->setDarkBorder(QWindowsContextPrivate::m_darkMode);
}
if (integration->darkModeHandling().testFlag(QWindowsApplication::DarkModeStyle)) {
QWindowsTheme::instance()->refresh();
QWindowSystemInterface::handleThemeChange();
}
if (integration->darkModeHandling().testFlag(QWindowsApplication::DarkModeWindowFrames)) {
for (QWindowsWindow *w : d->m_windows)
w->setDarkBorder(QWindowsContextPrivate::m_darkMode);
}
}
}
return d->m_screenManager.handleScreenChanges();

View File

@ -212,8 +212,7 @@ void QWindowsIntegrationPrivate::parseOptions(QWindowsIntegration *q, const QStr
QtWindows::ProcessDpiAwareness dpiAwareness = QtWindows::ProcessPerMonitorV2DpiAware;
int tabletAbsoluteRange = -1;
DarkModeHandling darkModeHandling = DarkModeHandlingFlag::DarkModeWindowFrames
| DarkModeHandlingFlag::DarkModeStyle;
DarkModeHandling darkModeHandling = DarkModeHandlingFlag::DarkModeWindowFrames;
m_options = ::parseOptions(paramList, &tabletAbsoluteRange, &dpiAwareness, &darkModeHandling);
q->setDarkModeHandling(darkModeHandling);
QWindowsFontDatabase::setFontOptions(m_options);

View File

@ -848,7 +848,15 @@ void WindowCreationData::fromWindow(const QWindow *w, const Qt::WindowFlags flag
static inline bool shouldApplyDarkFrame(const QWindow *w)
{
return w->isTopLevel() && !w->flags().testFlag(Qt::FramelessWindowHint);
if (!w->isTopLevel() || w->flags().testFlag(Qt::FramelessWindowHint))
return false;
if (QWindowsIntegration::instance()->darkModeHandling().testFlag(QWindowsApplication::DarkModeStyle))
return true;
// if the application supports a dark border, and the palette is dark (window background color
// is darker than the text), then turn dark-border support on, otherwise use a light border.
const QPalette defaultPalette;
return defaultPalette.color(QPalette::WindowText).lightness()
> defaultPalette.color(QPalette::Window).lightness();
}
QWindowsWindowData