Reset palette resolve mask in windows vista style

The palette set by windows vista style during polish doesn't allow style-
sheet style to override it.

This patch reset resolve mask for the palette set by windows vista style
and thus it can be overridden.

Fixes: QTBUG-115511
Change-Id: Ifcaf441f806cfa0273599b3dce83fdfaec3f5a66
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 4cf92d83c3a8966fd1716939829fdbd4642810e9)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Santhosh Kumar 2023-08-03 10:47:14 +02:00 committed by Qt Cherry-pick Bot
parent 68e2645da2
commit e9cf618a9d
3 changed files with 61 additions and 13 deletions

View File

@ -4669,6 +4669,7 @@ void QWindowsVistaStyle::polish(QWidget *widget)
QPalette pal = widget->palette();
pal.setColor(QPalette::ButtonText, QColor(21, 28, 85));
pal.setColor(QPalette::BrightText, QColor(7, 64, 229));
pal.setResolveMask(0);
widget->setPalette(pal);
}
#endif // QT_CONFIG(commandlinkbutton)
@ -4682,6 +4683,7 @@ void QWindowsVistaStyle::polish(QWidget *widget)
QColor textColor = QColor::fromRgb(bgRef);
QPalette pal;
pal.setColor(QPalette::All, QPalette::ToolTipText, textColor);
pal.setResolveMask(0);
widget->setPalette(pal);
}
} else if (qobject_cast<QMessageBox *> (widget)) {

View File

@ -496,8 +496,11 @@ void QApplicationPrivate::init()
void qt_init_tooltip_palette()
{
#if QT_CONFIG(tooltip)
if (const QPalette *toolTipPalette = QGuiApplicationPrivate::platformTheme()->palette(QPlatformTheme::ToolTipPalette))
QToolTip::setPalette(*toolTipPalette);
if (const QPalette *toolTipPalette = QGuiApplicationPrivate::platformTheme()->palette(QPlatformTheme::ToolTipPalette)) {
QPalette toolTipPal = *toolTipPalette;
toolTipPal.setResolveMask(0);
QToolTip::setPalette(toolTipPal);
}
#endif
}

View File

@ -38,7 +38,7 @@
#include <private/qstylesheetstyle_p.h>
#include <private/qhighdpiscaling_p.h>
#include <QtTest/private/qtesthelpers_p.h>
#include <qpa/qplatformtheme.h>
#include <QtWidgets/private/qapplication_p.h>
using namespace QTestPrivate;
@ -94,6 +94,7 @@ private slots:
void proxyStyle();
void dialogButtonBox();
void emptyStyleSheet();
void toolTip_data();
void toolTip();
void embeddedFonts();
void opaquePaintEvent_data();
@ -1658,19 +1659,32 @@ private:
const QString m_oldStyleName;
};
void tst_QStyleSheetStyle::toolTip_data()
{
QTest::addColumn<QString>("style");
QTest::newRow("fusion") << QString("Fusion");
#ifdef Q_OS_WINDOWS
QTest::newRow("windowsvista") << QString("WindowsVista");
#endif
}
void tst_QStyleSheetStyle::toolTip()
{
QFETCH(QString, style);
if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
QSKIP("Wayland: This fails. Figure out why.");
qApp->setStyleSheet(QString());
QWidget w;
w.resize(m_testSize);
w.setWindowTitle(QTest::currentTestFunction());
// Use "Fusion" to prevent the Vista style from clobbering the tooltip palette in polish().
QStyle *fusionStyle = QStyleFactory::create(QLatin1String("Fusion"));
QVERIFY(fusionStyle);
ApplicationStyleSetter as(fusionStyle);
QStyle *appStyle = QStyleFactory::create(style);
QVERIFY(appStyle);
ApplicationStyleSetter as(appStyle);
QHBoxLayout layout(&w);
w.setLayout(&layout);
@ -1698,23 +1712,41 @@ void tst_QStyleSheetStyle::toolTip()
wid4->setToolTip("this is wid4");
wid4->setObjectName("wid4");
QWidget *wid5 = new QPushButton("wid5", &w);
layout.addWidget(wid5);
wid5->setStyleSheet("QToolTip { background: #ff0; color: #f00 }");
wid5->setToolTip("this is wid5");
wid5->setObjectName("wid5");
centerOnScreen(&w);
w.show();
QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
const QColor normalToolTip = QToolTip::palette().color(QPalette::Inactive, QPalette::ToolTipBase);
QColor normalToolTipBgColor = QToolTip::palette().color(QPalette::Inactive, QPalette::ToolTipBase);
#ifdef Q_OS_MACOS
// macOS uses tool tip text color set in label palette
const QPalette *labelPalette = QGuiApplicationPrivate::platformTheme()->palette(QPlatformTheme::LabelPalette);
QColor normalToolTipFgColor = labelPalette->color(QPalette::Inactive, QPalette::ToolTipText);
#else
QColor normalToolTipFgColor = QToolTip::palette().color(QPalette::Inactive, QPalette::ToolTipText);
#endif
// Tooltip on the widget without stylesheet, then to other widget,
// including one without stylesheet (the tooltip will be reused,
// but its color must change)
const QWidgetList widgets{wid4, wid1, wid2, wid3, wid4};
const QList<QColor> colors { normalToolTip, QColor("#ae2"), QColor("#f81"), QColor("#0b8"),
normalToolTip };
const QWidgetList widgets{wid4, wid1, wid2, wid3, wid4, wid5};
const QList<QColor> bgcolors { normalToolTipBgColor, QColor("#ae2"), QColor("#f81"),
QColor("#0b8"), normalToolTipBgColor, QColor("#ff0")};
const QList<QColor> fgcolors { normalToolTipFgColor, normalToolTipFgColor, normalToolTipFgColor,
normalToolTipFgColor, normalToolTipFgColor, QColor("#f00")};
QWidgetList topLevels;
for (int i = 0; i < widgets.size() ; ++i) {
QWidget *wid = widgets.at(i);
QColor col = colors.at(i);
QColor bgColor = bgcolors.at(i);
QColor fgColor = fgcolors.at(i);
QToolTip::showText( QPoint(0,0) , "This is " + wid->objectName(), wid);
@ -1726,9 +1758,20 @@ void tst_QStyleSheetStyle::toolTip()
break;
}
}
QVERIFY(tooltip);
QTRY_VERIFY(tooltip->isVisible()); // Wait until Roll-Effect is finished (Windows Vista)
QCOMPARE(tooltip->palette().color(tooltip->backgroundRole()), col);
#ifdef Q_OS_WINDOWS
// If tooltip palette contains empty resolve mask, validate with inherited palette
if (!tooltip->palette().resolveMask()) {
bgColor = w.palette().color(tooltip->backgroundRole());
fgColor = w.palette().color(tooltip->foregroundRole());
}
#endif
QCOMPARE(tooltip->palette().color(tooltip->backgroundRole()), bgColor);
QCOMPARE(tooltip->palette().color(tooltip->foregroundRole()), fgColor);
}
QToolTip::showText( QPoint(0,0) , "This is " + wid3->objectName(), wid3);