QTableView: update editor geometries directly after scrollbars are adjusted
QTableView::doItemsLayout() updated the scroll offset for the vertical header after layouting was done. Since the scroll offset affects the viewport of the editors, the adjustment was done too late. Therefore we update the scroll offset right after the scrollbars are set inside QTableView::updateGeometries() [ChangeLog][QtWidgets][QTableView] Fixed calculating geometries for editors Task-number: QTBUG-48244 Task-number: QTBUG-49548 Change-Id: I3b057764cf99d42d861928a1c73277d34b440f9a Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
parent
5ba5a7b5bc
commit
451fcee8a8
@ -1176,7 +1176,6 @@ void QTableView::doItemsLayout()
|
||||
{
|
||||
Q_D(QTableView);
|
||||
QAbstractItemView::doItemsLayout();
|
||||
d->verticalHeader->d_func()->setScrollOffset(verticalScrollBar(), verticalScrollMode());
|
||||
if (!d->verticalHeader->updatesEnabled())
|
||||
d->verticalHeader->setUpdatesEnabled(true);
|
||||
}
|
||||
@ -2223,6 +2222,7 @@ void QTableView::updateGeometries()
|
||||
verticalScrollBar()->setRange(0, verticalLength - vsize.height());
|
||||
verticalScrollBar()->d_func()->itemviewChangeSingleStep(qMax(vsize.height() / (rowsInViewport + 1), 2));
|
||||
}
|
||||
d->verticalHeader->d_func()->setScrollOffset(verticalScrollBar(), verticalScrollMode());
|
||||
|
||||
d->geometryRecursionBlock = false;
|
||||
QAbstractItemView::updateGeometries();
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <qlist.h>
|
||||
#include <qpair.h>
|
||||
#include <qheaderview.h>
|
||||
#include <qlineedit.h>
|
||||
|
||||
#include <qtablewidget.h>
|
||||
|
||||
@ -81,6 +82,7 @@ private slots:
|
||||
void itemData();
|
||||
void setItemData();
|
||||
void cellWidget();
|
||||
void cellWidgetGeometry();
|
||||
void task231094();
|
||||
void task219380_removeLastRow();
|
||||
void task262056_sortDuplicate();
|
||||
@ -1423,6 +1425,28 @@ void tst_QTableWidget::cellWidget()
|
||||
QCOMPARE(table.cellWidget(5, 5), static_cast<QWidget*>(0));
|
||||
}
|
||||
|
||||
void tst_QTableWidget::cellWidgetGeometry()
|
||||
{
|
||||
QTableWidget tw(3,2);
|
||||
tw.show();
|
||||
// make sure the next row added is not completely visibile
|
||||
tw.resize(300, tw.rowHeight(0) * 3 + tw.rowHeight(0) / 2);
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&tw));
|
||||
|
||||
tw.scrollToBottom();
|
||||
tw.setRowCount(tw.rowCount() + 1);
|
||||
auto item = new QTableWidgetItem("Hello");
|
||||
tw.setItem(0,0,item);
|
||||
auto le = new QLineEdit("world");
|
||||
tw.setCellWidget(0,1,le);
|
||||
// process delayedPendingLayout triggered by setting the row count
|
||||
tw.doItemsLayout();
|
||||
// so y pos is 0 for the first row
|
||||
tw.scrollToTop();
|
||||
// check if updateEditorGeometries has set the correct y pos for the editors
|
||||
QCOMPARE(tw.visualItemRect(item).top(), le->geometry().top());
|
||||
}
|
||||
|
||||
void tst_QTableWidget::task231094()
|
||||
{
|
||||
QTableWidget tw(5, 3);
|
||||
|
Loading…
Reference in New Issue
Block a user