summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/itemviews
diff options
context:
space:
mode:
authorTang Haixiang <tanghaixiang@uniontech.com>2021-04-27 17:39:48 +0800
committerTang Haixiang <tanghaixiang@uniontech.com>2021-05-31 03:27:12 +0000
commitc77840d734883c91079c942e052cbdc0994c2f01 (patch)
treea8d0771493c859dbf35693aa8a058fe2373c57e9 /tests/auto/widgets/itemviews
parent80cf470534c3ce2a4f9c3cb8c6795e5342f2d932 (diff)
Fix PageDown behavior and PageUP
When the PageDown is pressed, the current's rect cannot be used to match the item, because we don't know the size of the rect. Move the rect by the height of the viewport, and then move the rect upwards until it matches the button <= viewport's bottom of the item Fixes: QTBUG-92583 Pick-to: 6.1 Change-Id: I210edc0e8b942984f3fc20e7752c6e1315152ea1 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto/widgets/itemviews')
-rw-r--r--tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
index 3768acade7..8948f02a8b 100644
--- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
+++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
@@ -109,6 +109,7 @@ private slots:
void moveCursor();
void moveCursor2();
void moveCursor3();
+ void moveCursor4();
void indexAt();
void clicked();
void singleSelectionRemoveRow();
@@ -573,6 +574,56 @@ void tst_QListView::moveCursor3()
QCOMPARE(view.selectionModel()->currentIndex(), model.index(0, 0));
}
+void tst_QListView::moveCursor4()
+{
+ int indexCount = 100;
+ PublicListView listView;
+ QStandardItemModel model;
+ for (int i = 0; i < 100; i++)
+ {
+ QStandardItem* item = new QStandardItem(QString("item 0%0").arg(i));
+ QFont font = item->font();
+ font.setPixelSize(14);
+ item->setFont(font);
+ model.appendRow(item);
+ }
+ QFont font = model.item(0)->font();
+ font.setPixelSize(50);
+ font.setBold(true);
+ model.item(0)->setFont(font);
+ listView.setModel(&model);
+ listView.setFixedSize(200, 200);
+ listView.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ listView.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ listView.show();
+ listView.selectionModel()->setCurrentIndex(model.index(0, 0), QItemSelectionModel::SelectCurrent);
+
+ QModelIndex idx = listView.moveCursor(PublicListView::MovePageDown, Qt::NoModifier);
+
+ int actualIndex = 0;
+ int indexHeight = 0;
+ while (indexHeight <= listView.viewport()->height()) {
+ indexHeight += listView.visualRect(model.item(actualIndex)->index()).height();
+ actualIndex++;
+ }
+ QTRY_COMPARE(idx, model.index(actualIndex - 2, 0));
+ idx = listView.moveCursor(PublicListView::MoveUp, Qt::NoModifier);
+ QTRY_COMPARE(idx, model.index(0, 0));
+
+ listView.setCurrentIndex(model.index(indexCount - 2, 0));
+ idx = listView.moveCursor(PublicListView::MovePageDown, Qt::NoModifier);
+ QTRY_COMPARE(idx, model.index(99, 0));
+
+ listView.setCurrentIndex(model.index(3, 0));
+ actualIndex = 3;
+ indexHeight = 0;
+ while (indexHeight <= listView.viewport()->height()) {
+ indexHeight += listView.visualRect(model.item(actualIndex)->index()).height();
+ actualIndex++;
+ }
+ idx = listView.moveCursor(PublicListView::MovePageDown, Qt::NoModifier);
+ QTRY_COMPARE(idx, model.index(actualIndex - 2, 0));
+}
class QListViewShowEventListener : public QListView
{