QAbstractItemView: Make sure to update the editor geometries

QAbstractItemView::setIndexWidget() does not trigger a relayouting when
a new widget is set. This results in a wrong editor geometry under some
circumstances. Fix it by triggering a delayed relayout.

Fixes: QTBUG-81763
Change-Id: I75d0e19bd5e56d63effe4990d782d202fb39e3e6
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
Christian Ehrlicher 2020-02-03 20:26:22 +01:00
parent 835e18d9ff
commit 875420f1c2
2 changed files with 5 additions and 1 deletions

View File

@ -3234,8 +3234,10 @@ void QAbstractItemView::setIndexWidget(const QModelIndex &index, QWidget *widget
widget->installEventFilter(this);
widget->show();
dataChanged(index, index); // update the geometry
if (!d->delayedPendingLayout)
if (!d->delayedPendingLayout) {
widget->setGeometry(visualRect(index));
d->doDelayedItemsLayout(); // relayout due to updated geometry
}
}
}

View File

@ -952,6 +952,7 @@ void tst_QTreeView::indexWidget()
QStandardItemModel treeModel;
initStandardTreeModel(&treeModel);
view.setModel(&treeModel);
view.resize(300, 400); // make sure the width of the view is larger than the widgets below
QModelIndex index = view.model()->index(0, 0);
@ -980,6 +981,7 @@ void tst_QTreeView::indexWidget()
//now let's try to do that later when the widget is already shown
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
index = view.model()->index(1, 0);
QVERIFY(!view.indexWidget(index));