diff options
Diffstat (limited to 'tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp')
-rw-r--r-- | tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index d8bb34933a..7af60ed757 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -167,6 +167,7 @@ private slots: void task_QTBUG_52027_mapCompleterIndex(); void checkMenuItemPosWhenStyleSheetIsSet(); void checkEmbeddedLineEditWhenStyleSheetIsSet(); + void propagateStyleChanges(); private: PlatformInputContext m_platformInputContext; @@ -1681,6 +1682,16 @@ void tst_QComboBox::setModel() QCOMPARE(box.rootModelIndex(), rootModelIndex); box.setModel(box.model()); QCOMPARE(box.rootModelIndex(), rootModelIndex); + + // check that setting the same model as the completer's doesn't crash + QCompleter *completer = new QCompleter(&box); + box.setEditable(true); + box.setCompleter(completer); + auto *listModel = new QStringListModel({ "one", "two" }, completer); + completer->setModel(listModel); + QCOMPARE(listModel->rowCount(), 2); // make sure it wasn't deleted + box.setModel(listModel); + QCOMPARE(listModel->rowCount(), 2); // make sure it wasn't deleted } void tst_QComboBox::setCustomModelAndView() @@ -3586,5 +3597,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" |