diff options
author | David Faure <david.faure@kdab.com> | 2015-03-30 10:20:07 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-04-04 12:24:44 +0000 |
commit | 5aa40e5b00eb8f54157bc1aa01205a8a87e0c661 (patch) | |
tree | 3796ef2c1d1c554d93fbdbd73b6d8ef596d7d6a5 | |
parent | ddb0628181ba6f2ebeedf7e8f4186861ab63b628 (diff) |
QComboBox: also adjust size on model reset, with AdjustToContents
When the size adjust policy is QComboBox::AdjustToContents, the combobox
sizeHint was recalculated on dataChanged, rowsInserted, rowsRemoved,
and setModel, but not when the model was reset. This led to truncated
items in the combobox when models are filled asynchronously.
Task-number: QTBUG-5413
Change-Id: I3456c327d680dfffa58d6dcb26c79456c67b2a32
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
-rw-r--r-- | src/widgets/widgets/qcombobox.cpp | 1 | ||||
-rw-r--r-- | tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp | 17 |
2 files changed, 18 insertions, 0 deletions
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() |