From 7fdf7ad7e578675b32deb399b51ec6392c66cb2d Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Tue, 1 Apr 2025 21:36:13 +0200 Subject: [PATCH] Windows11Style: replace QObject::inherits() with qobject_cast<> Use qobject_cast instead QObject::inherits() as this should be slightly faster and we have access to the type so no need to use error-prone string comparison. Pick-to: 6.9 6.8 Task-number: QTBUG-135340 Change-Id: I90ebb2323f21c2f5f9dd65bd7b1beeb32f1a91cc Reviewed-by: Wladimir Leuschner --- src/plugins/styles/modernwindows/qwindows11style.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/plugins/styles/modernwindows/qwindows11style.cpp b/src/plugins/styles/modernwindows/qwindows11style.cpp index ac98aaa5900..7566e00fd9e 100644 --- a/src/plugins/styles/modernwindows/qwindows11style.cpp +++ b/src/plugins/styles/modernwindows/qwindows11style.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -978,7 +979,7 @@ void QWindows11Style::drawPrimitive(PrimitiveElement element, const QStyleOption if (frame->frameShape == QFrame::NoFrame) break; QRectF rect = option->rect.adjusted(1,1,-1,-1); - if (widget && widget->inherits("QComboBoxPrivateContainer")) { + if (qobject_cast(widget)) { painter->setPen(Qt::NoPen); painter->setBrush(WINUI3Colors[colorSchemeIndex][menuPanelFill]); painter->drawRoundedRect(rect, secondLevelRoundingRadius, secondLevelRoundingRadius); @@ -1853,8 +1854,7 @@ QRect QWindows11Style::subElementRect(QStyle::SubElement element, const QStyleOp if (const auto *item = qstyleoption_cast(option)) { const int decorationOffset = item->features.testFlag(QStyleOptionViewItem::HasDecoration) ? item->decorationSize.width() : 0; const int checkboxOffset = item->features.testFlag(QStyleOptionViewItem::HasCheckIndicator) ? 16 : 0; - if (widget && widget->parentWidget() - && widget->parentWidget()->inherits("QComboBoxPrivateContainer")) { + if (widget && qobject_cast(widget->parentWidget())) { if (option->direction == Qt::LeftToRight) ret = option->rect.adjusted(decorationOffset + checkboxOffset + 5, 0, -5, 0); else @@ -2197,7 +2197,8 @@ void QWindows11Style::polish(QWidget* widget) if (!qobject_cast(widget)) QWindowsVistaStyle::polish(widget); const bool isScrollBar = qobject_cast(widget); - if (isScrollBar || qobject_cast(widget) || widget->inherits("QComboBoxPrivateContainer")) { + const auto comboBoxContainer = qobject_cast(widget); + if (isScrollBar || qobject_cast(widget) || comboBoxContainer) { bool wasCreated = widget->testAttribute(Qt::WA_WState_Created); bool layoutDirection = widget->testAttribute(Qt::WA_RightToLeft); widget->setAttribute(Qt::WA_OpaquePaintEvent,false);