From 755e6e6a6da462522a814a0d1e922b03692e2104 Mon Sep 17 00:00:00 2001 From: Oliver Eftevaag Date: Wed, 7 May 2025 13:40:21 +0200 Subject: [PATCH] Windowsvista style: Fix hover widget attribute when using contrast theme The windows vista style sets the widget attribute for certain widgets to have the Qt::WA_Hover attribute, which makes the widget eligible for receiving hover events from QApplication::notify(QObject*, QEvent*). However, if the windows system had enabled a high contrast theme, the QWindowsVistaStyle::polish(QWidget*) function would return early, without making any widgets eligible for receiving hover events. Fix the issue by enabling hover events for select controls first, before potentially returning early due to using a contrast theme. Pick-to: 6.8 Change-Id: I5562f46385c6f1b498bc659c65e501f9e9376db3 Reviewed-by: Santhosh Kumar (cherry picked from commit 4720b592d729982faf85093b7511457b4945cf8d) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit 6874de0e509b59acafe8ff9b67bb3aa7ab4756fc) --- .../modernwindows/qwindowsvistastyle.cpp | 51 +++++++++---------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/src/plugins/styles/modernwindows/qwindowsvistastyle.cpp b/src/plugins/styles/modernwindows/qwindowsvistastyle.cpp index 5b7822b651d..c796dbd6a0d 100644 --- a/src/plugins/styles/modernwindows/qwindowsvistastyle.cpp +++ b/src/plugins/styles/modernwindows/qwindowsvistastyle.cpp @@ -4596,9 +4596,6 @@ int QWindowsVistaStyle::pixelMetric(PixelMetric metric, const QStyleOption *opti void QWindowsVistaStyle::polish(QWidget *widget) { QWindowsStyle::polish(widget); - if (!QWindowsVistaStylePrivate::useVista()) - return; - if (false #if QT_CONFIG(abstractbutton) || qobject_cast(widget) @@ -4619,35 +4616,39 @@ void QWindowsVistaStyle::polish(QWidget *widget) || qobject_cast(widget) || qobject_cast(widget) #endif // QT_CONFIG(spinbox) +#if QT_CONFIG(lineedit) + || qobject_cast(widget) +#endif // QT_CONFIG(lineedit) + || qobject_cast(widget) ) { widget->setAttribute(Qt::WA_Hover); + } else if (QTreeView *tree = qobject_cast (widget)) { + tree->viewport()->setAttribute(Qt::WA_Hover); + } else if (QListView *list = qobject_cast (widget)) { + list->viewport()->setAttribute(Qt::WA_Hover); } + if (!QWindowsVistaStylePrivate::useVista()) + return; + #if QT_CONFIG(rubberband) if (qobject_cast(widget)) widget->setWindowOpacity(0.6); -#endif - -#if QT_CONFIG(lineedit) - if (qobject_cast(widget)) - widget->setAttribute(Qt::WA_Hover); else -#endif // QT_CONFIG(lineedit) - if (qobject_cast(widget)) - widget->setAttribute(Qt::WA_Hover); +#endif #if QT_CONFIG(commandlinkbutton) - else if (qobject_cast(widget)) { - widget->setProperty("_qt_usingVistaStyle", true); - QFont buttonFont = widget->font(); - buttonFont.setFamilies(QStringList{QLatin1String("Segoe UI")}); - widget->setFont(buttonFont); - QPalette pal = widget->palette(); - pal.setColor(QPalette::Active, QPalette::ButtonText, QColor(21, 28, 85)); - pal.setColor(QPalette::Active, QPalette::BrightText, QColor(7, 64, 229)); - widget->setPalette(pal); - } + if (qobject_cast(widget)) { + widget->setProperty("_qt_usingVistaStyle", true); + QFont buttonFont = widget->font(); + buttonFont.setFamilies(QStringList{QLatin1String("Segoe UI")}); + widget->setFont(buttonFont); + QPalette pal = widget->palette(); + pal.setColor(QPalette::Active, QPalette::ButtonText, QColor(21, 28, 85)); + pal.setColor(QPalette::Active, QPalette::BrightText, QColor(7, 64, 229)); + widget->setPalette(pal); + } else #endif // QT_CONFIG(commandlinkbutton) - else if (widget->inherits("QTipLabel")) { + if (widget->inherits("QTipLabel")) { //note that since tooltips are not reused //we do not have to care about unpolishing widget->setContentsMargins(3, 0, 4, 0); @@ -4678,12 +4679,6 @@ void QWindowsVistaStyle::polish(QWidget *widget) #endif } #endif // QT_CONFIG(inputdialog) - else if (QTreeView *tree = qobject_cast (widget)) { - tree->viewport()->setAttribute(Qt::WA_Hover); - } - else if (QListView *list = qobject_cast (widget)) { - list->viewport()->setAttribute(Qt::WA_Hover); - } } /*!