diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 390478f911..76f923904d 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -226,6 +226,7 @@ void QComboBoxPrivate::_q_modelReset() } if (currentIndex.row() != indexBeforeChange) _q_emitCurrentIndexChanged(currentIndex); + modelChanged(); q->update(); } diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index 97416135db..c409698ec0 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -531,6 +531,23 @@ void tst_QComboBox::sizeAdjustPolicy() QCOMPARE(testWidget->sizeHint(), content); testWidget->setMinimumContentsLength(0); QVERIFY(testWidget->sizeHint().width() < content.width()); + + // check AdjustToContents changes when model changes + content = testWidget->sizeHint(); + QStandardItemModel *model = new QStandardItemModel(2, 1, testWidget); + testWidget->setModel(model); + QVERIFY(testWidget->sizeHint().width() < content.width()); + + // check AdjustToContents changes when a row is inserted into the model + content = testWidget->sizeHint(); + QStandardItem *item = new QStandardItem(QStringLiteral("This is an item")); + model->appendRow(item); + QVERIFY(testWidget->sizeHint().width() > content.width()); + + // check AdjustToContents changes when model is reset + content = testWidget->sizeHint(); + model->clear(); + QVERIFY(testWidget->sizeHint().width() < content.width()); } void tst_QComboBox::clear()