From 875420f1c29f0d5e66b4dcacbe95d31dd5dca585 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Mon, 3 Feb 2020 20:26:22 +0100 Subject: [PATCH] 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 --- src/widgets/itemviews/qabstractitemview.cpp | 4 +++- tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index c3f8dd894e..f879af6ad2 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -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 + } } } diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp index b2ca62227f..0580c466cf 100644 --- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp @@ -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));