From 170fadadd67fa97621a7782ea845c314bd9ee09d Mon Sep 17 00:00:00 2001 From: Santhosh Kumar Date: Sun, 26 Feb 2023 08:56:35 +0100 Subject: Add API in QWindowsPrivate to provide window palette The window uses default palette (QPalette()) to determine frame color (either light or dark). This doesn't work for quickcontrols as they depend quicktheme palettes and they don't overwrite default palettes. This patch add API in QWindowPrivate to provide palette for window and this can be overridden by quickcontrol windows to provide their corresponding palette. Fixes: QTBUG-111491 Pick-to: 6.5 Change-Id: I39eea20ee7c61ecf0279143c9784da35be15edd3 Reviewed-by: Volker Hilsheimer --- src/gui/kernel/qwindow_p.h | 4 +++- src/plugins/platforms/windows/qwindowswindow.cpp | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/gui/kernel/qwindow_p.h b/src/gui/kernel/qwindow_p.h index cf6a6934eb..ef633d093a 100644 --- a/src/gui/kernel/qwindow_p.h +++ b/src/gui/kernel/qwindow_p.h @@ -23,7 +23,8 @@ #include #include #include -#include +#include +#include QT_BEGIN_NAMESPACE @@ -53,6 +54,7 @@ public: QWindow *topLevelWindow(QWindow::AncestorMode mode = QWindow::IncludeTransients) const; virtual QWindow *eventReceiver() { Q_Q(QWindow); return q; } + virtual QPalette windowPalette() const { return QPalette(); } virtual void setVisible(bool visible); void updateVisibility(); diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 7dec51c4cc..6fcc226abc 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -845,11 +845,13 @@ static inline bool shouldApplyDarkFrame(const QWindow *w) // the application has explicitly opted out of dark frames if (!QWindowsIntegration::instance()->darkModeHandling().testFlag(QWindowsApplication::DarkModeWindowFrames)) return false; + // 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(); + auto *dWindow = QWindowPrivate::get(const_cast(w)); + const QPalette windowPal = dWindow->windowPalette(); + return windowPal.color(QPalette::WindowText).lightness() + > windowPal.color(QPalette::Window).lightness(); } QWindowsWindowData -- cgit v1.2.1