From 9da8d67b3bca1d40ae221a9c6be218fe57759724 Mon Sep 17 00:00:00 2001 From: Wladimir Leuschner Date: Thu, 1 Jun 2023 14:45:47 +0300 Subject: Introduce Windows 11 styled ComboBox in QWindows11Style QComboBox is adapted to use the WinUI3 style. Task-number: QTBUG-113513 Change-Id: I300157a7ce9162be73ccd4acfc50b12f7166dc2d Reviewed-by: Oliver Wolff --- src/widgets/widgets/qcombobox.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/widgets/widgets/qcombobox.cpp') diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index b7a084364b..937076a7b5 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -761,7 +761,9 @@ bool QComboBoxPrivateContainer::eventFilter(QObject *o, QEvent *e) QModelIndex indexUnderMouse = view->indexAt(m->position().toPoint()); if (indexUnderMouse.isValid() && !QComboBoxDelegate::isSeparator(indexUnderMouse)) { - view->setCurrentIndex(indexUnderMouse); + // Request for comments: To show selected item with AccentColor bar indicator and hovered + // items in the flyout, the next line needs to be removed. + //view->setCurrentIndex(indexUnderMouse); } } break; @@ -2969,9 +2971,26 @@ void QComboBox::changeEvent(QEvent *e) Q_D(QComboBox); switch (e->type()) { case QEvent::StyleChange: - if (d->container) + if (d->container) { +// If on Windows, force recreation of ComboBox container, since +// windows11 style depends on WA_TranslucentBackground +#ifdef Q_OS_WIN + auto delegate = itemDelegate(); + d->container->deleteLater(); + // d->container needs to be set explicitly to nullptr + // since QComboBoxPrivate::viewContainer() only + // creates a new QComboBoxPrivateContainer when + // d->container has the value of nullptr + d->container = nullptr; + d->container = d->viewContainer(); + delegate->setParent(d->container); + setItemDelegate(delegate); + +#endif d->container->updateStyleSettings(); + } d->updateDelegate(); + #ifdef Q_OS_MAC case QEvent::MacSizeChange: #endif -- cgit v1.2.3