Fix QTableView::doItemsLayout()
Keep the content aligned to the bottom when the view has been scrolled to the bottom and the content is relayouted (for example due to sorting). Task-number: QTBUG-30653 Change-Id: I9513e295e276d25ff2068036cd80dbf91314fe84 Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com> Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
parent
241ee2ee42
commit
00b11ccdea
@ -1113,10 +1113,15 @@ void QTableView::doItemsLayout()
|
||||
{
|
||||
Q_D(QTableView);
|
||||
QAbstractItemView::doItemsLayout();
|
||||
if (verticalScrollMode() == QAbstractItemView::ScrollPerItem)
|
||||
d->verticalHeader->setOffsetToSectionPosition(verticalScrollBar()->value());
|
||||
else
|
||||
if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) {
|
||||
const int max = verticalScrollBar()->maximum();
|
||||
if (max > 0 && verticalScrollBar()->value() == max)
|
||||
d->verticalHeader->setOffsetToLastSection();
|
||||
else
|
||||
d->verticalHeader->setOffsetToSectionPosition(verticalScrollBar()->value());
|
||||
} else {
|
||||
d->verticalHeader->setOffset(verticalScrollBar()->value());
|
||||
}
|
||||
if (!d->verticalHeader->updatesEnabled())
|
||||
d->verticalHeader->setUpdatesEnabled(true);
|
||||
}
|
||||
|
@ -199,6 +199,7 @@ private slots:
|
||||
void taskQTBUG_7774_RtoLVisualRegionForSelection();
|
||||
void taskQTBUG_8777_scrollToSpans();
|
||||
void taskQTBUG_10169_sizeHintForRow();
|
||||
void taskQTBUG_30653_doItemsLayout();
|
||||
|
||||
void mouseWheel_data();
|
||||
void mouseWheel();
|
||||
@ -4096,5 +4097,38 @@ void tst_QTableView::viewOptions()
|
||||
QVERIFY(options.showDecorationSelected);
|
||||
}
|
||||
|
||||
void tst_QTableView::taskQTBUG_30653_doItemsLayout()
|
||||
{
|
||||
QWidget topLevel;
|
||||
QtTestTableView view(&topLevel);
|
||||
|
||||
QtTestTableModel model(5, 5);
|
||||
view.setModel(&model);
|
||||
|
||||
QtTestItemDelegate delegate;
|
||||
delegate.hint = QSize(50, 50);
|
||||
view.setItemDelegate(&delegate);
|
||||
|
||||
view.resizeRowsToContents();
|
||||
view.resizeColumnsToContents();
|
||||
|
||||
// show two and half rows/cols
|
||||
int extraWidth = view.verticalHeader()->sizeHint().width() + view.verticalScrollBar()->sizeHint().width();
|
||||
int extraHeight = view.horizontalHeader()->sizeHint().height() + view.horizontalScrollBar()->sizeHint().height();
|
||||
view.resize(125 + extraWidth, 125 + extraHeight);
|
||||
|
||||
topLevel.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&topLevel));
|
||||
|
||||
// the offset after scrollToBottom() and doItemsLayout() should not differ
|
||||
// as the view content should stay aligned to the last section
|
||||
view.scrollToBottom();
|
||||
int scrollToBottomOffset = view.verticalHeader()->offset();
|
||||
view.doItemsLayout();
|
||||
int doItemsLayoutOffset = view.verticalHeader()->offset();
|
||||
|
||||
QCOMPARE(scrollToBottomOffset, doItemsLayoutOffset);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QTableView)
|
||||
#include "tst_qtableview.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user