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
Change-Id: I39eea20ee7c61ecf0279143c9784da35be15edd3
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 170fadadd67fa97621a7782ea845c314bd9ee09d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Santhosh Kumar 2023-02-26 08:56:35 +01:00 committed by Qt Cherry-pick Bot
parent 8269d5cd82
commit 7b96dad1e9
2 changed files with 8 additions and 4 deletions

View File

@ -23,7 +23,8 @@
#include <QtCore/private/qobject_p.h> #include <QtCore/private/qobject_p.h>
#include <QtCore/qelapsedtimer.h> #include <QtCore/qelapsedtimer.h>
#include <QtCore/qxpfunctional.h> #include <QtCore/qxpfunctional.h>
#include <QtGui/QIcon> #include <QtGui/qicon.h>
#include <QtGui/qpalette.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -53,6 +54,7 @@ public:
QWindow *topLevelWindow(QWindow::AncestorMode mode = QWindow::IncludeTransients) const; QWindow *topLevelWindow(QWindow::AncestorMode mode = QWindow::IncludeTransients) const;
virtual QWindow *eventReceiver() { Q_Q(QWindow); return q; } virtual QWindow *eventReceiver() { Q_Q(QWindow); return q; }
virtual QPalette windowPalette() const { return QPalette(); }
virtual void setVisible(bool visible); virtual void setVisible(bool visible);
void updateVisibility(); void updateVisibility();

View File

@ -852,11 +852,13 @@ static inline bool shouldApplyDarkFrame(const QWindow *w)
// the application has explicitly opted out of dark frames // the application has explicitly opted out of dark frames
if (!QWindowsIntegration::instance()->darkModeHandling().testFlag(QWindowsApplication::DarkModeWindowFrames)) if (!QWindowsIntegration::instance()->darkModeHandling().testFlag(QWindowsApplication::DarkModeWindowFrames))
return false; return false;
// if the application supports a dark border, and the palette is dark (window background color // 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. // is darker than the text), then turn dark-border support on, otherwise use a light border.
const QPalette defaultPalette; auto *dWindow = QWindowPrivate::get(const_cast<QWindow*>(w));
return defaultPalette.color(QPalette::WindowText).lightness() const QPalette windowPal = dWindow->windowPalette();
> defaultPalette.color(QPalette::Window).lightness(); return windowPal.color(QPalette::WindowText).lightness()
> windowPal.color(QPalette::Window).lightness();
} }
QWindowsWindowData QWindowsWindowData