diff options
-rw-r--r-- | src/widgets/widgets/qcombobox.cpp | 24 | ||||
-rw-r--r-- | src/widgets/widgets/qcombobox_p.h | 1 | ||||
-rw-r--r-- | tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp | 46 |
3 files changed, 62 insertions, 9 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index c4596d9e78..4e2f9c23a0 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -531,8 +531,6 @@ QComboBoxPrivateContainer::QComboBoxPrivateContainer(QAbstractItemView *itemView setLineWidth(1); } - setFrameStyle(combo->style()->styleHint(QStyle::SH_ComboBox_PopupFrameStyle, &opt, combo)); - if (top) { layout->insertWidget(0, top); connect(top, SIGNAL(doScroll(int)), this, SLOT(scrollItemView(int))); @@ -545,7 +543,7 @@ QComboBoxPrivateContainer::QComboBoxPrivateContainer(QAbstractItemView *itemView // Some styles (Mac) have a margin at the top and bottom of the popup. layout->insertSpacing(0, 0); layout->addSpacing(0); - updateTopBottomMargin(); + updateStyleSettings(); } void QComboBoxPrivateContainer::scrollItemView(int action) @@ -728,14 +726,20 @@ void QComboBoxPrivateContainer::updateTopBottomMargin() boxLayout->invalidate(); } +void QComboBoxPrivateContainer::updateStyleSettings() +{ + // add scroller arrows if style needs them + QStyleOptionComboBox opt = comboStyleOption(); + view->setMouseTracking(combo->style()->styleHint(QStyle::SH_ComboBox_ListMouseTracking, &opt, combo) || + combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo)); + setFrameStyle(combo->style()->styleHint(QStyle::SH_ComboBox_PopupFrameStyle, &opt, combo)); + updateTopBottomMargin(); +} + void QComboBoxPrivateContainer::changeEvent(QEvent *e) { - if (e->type() == QEvent::StyleChange) { - QStyleOptionComboBox opt = comboStyleOption(); - view->setMouseTracking(combo->style()->styleHint(QStyle::SH_ComboBox_ListMouseTracking, &opt, combo) || - combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo)); - setFrameStyle(combo->style()->styleHint(QStyle::SH_ComboBox_PopupFrameStyle, &opt, combo)); - } + if (e->type() == QEvent::StyleChange) + updateStyleSettings(); QFrame::changeEvent(e); } @@ -2966,6 +2970,8 @@ void QComboBox::changeEvent(QEvent *e) Q_D(QComboBox); switch (e->type()) { case QEvent::StyleChange: + if (d->container) + d->container->updateStyleSettings(); d->updateDelegate(); #ifdef Q_OS_MAC case QEvent::MacSizeChange: diff --git a/src/widgets/widgets/qcombobox_p.h b/src/widgets/widgets/qcombobox_p.h index 16ded8f1a4..df3421692f 100644 --- a/src/widgets/widgets/qcombobox_p.h +++ b/src/widgets/widgets/qcombobox_p.h @@ -222,6 +222,7 @@ public: int topMargin() const; int bottomMargin() const { return topMargin(); } void updateTopBottomMargin(); + void updateStyleSettings(); QTimer blockMouseReleaseTimer; QBasicTimer adjustSizeTimer; diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index 909b0b4aaa..162b90d16b 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -169,6 +169,7 @@ private slots: void task_QTBUG_52027_mapCompleterIndex(); void checkMenuItemPosWhenStyleSheetIsSet(); void checkEmbeddedLineEditWhenStyleSheetIsSet(); + void propagateStyleChanges(); private: PlatformInputContext m_platformInputContext; @@ -3544,5 +3545,50 @@ void tst_QComboBox::checkEmbeddedLineEditWhenStyleSheetIsSet() qApp->setStyleSheet(oldCss); } +/*! + Tests that the style-based frame style propagates to the internal container + widget of QComboBox when the style changes by verifying that the respective + styleHint is asked for when the style changes. + + See QTBUG-92488 +*/ +void tst_QComboBox::propagateStyleChanges() +{ + class FrameStyle : public QProxyStyle + { + public: + FrameStyle(int frameStyle, QStyle *style = nullptr) + : QProxyStyle(style), frameStyle(frameStyle) + {} + + int styleHint(QStyle::StyleHint hint, const QStyleOption *opt, + const QWidget *widget, QStyleHintReturn *returnData) const + { + if (hint == QStyle::SH_ComboBox_PopupFrameStyle) { + inquired = true; + return frameStyle; + } + return QProxyStyle::styleHint(hint, opt, widget, returnData); + } + + int frameStyle; + mutable bool inquired = false; + }; + + FrameStyle framelessStyle(QFrame::NoFrame); + FrameStyle frameStyle(QFrame::Plain | QFrame::Sunken); + + QComboBox combo; + // container will be created and take settings from this style + combo.setStyle(&framelessStyle); + QVERIFY(framelessStyle.inquired); + combo.addItem(QLatin1String("Open")); + combo.addItem(QLatin1String("Close")); + // needed because of QComboBox's adjustSizeTimer not doing anything otherwise + combo.setSizeAdjustPolicy(QComboBox::AdjustToContents); + combo.setStyle(&frameStyle); + QVERIFY(frameStyle.inquired); +} + QTEST_MAIN(tst_QComboBox) #include "tst_qcombobox.moc" |