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>
This commit is contained in:
David Faure 2015-03-30 10:20:07 +02:00 committed by Marc Mutz
parent ddb0628181
commit 5aa40e5b00
2 changed files with 18 additions and 0 deletions

View File

@ -226,6 +226,7 @@ void QComboBoxPrivate::_q_modelReset()
}
if (currentIndex.row() != indexBeforeChange)
_q_emitCurrentIndexChanged(currentIndex);
modelChanged();
q->update();
}

View File

@ -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()