summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorJani Honkonen <jani.honkonen@digia.com>2012-02-28 10:26:22 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-08-22 00:59:03 (GMT)
commit1de75716d6f0691cc57feb21768f250236eebfd4 (patch)
tree67e4247ab40c82e304726e7b10822e3bf3794cfa /tests/auto
parent1cc7a13c71240507a5c6aa31fdf63e2db30d4117 (diff)
downloadQt-1de75716d6f0691cc57feb21768f250236eebfd4.zip
Qt-1de75716d6f0691cc57feb21768f250236eebfd4.tar.gz
Qt-1de75716d6f0691cc57feb21768f250236eebfd4.tar.bz2
Fix QListWidget scrolling with keys when there are hidden items
If the selected item is scrolled with keyboard keys the selected item will go outside the visible area. The scrolling did not take hidden items into account when calculating the amout to be scrolled. Backported from Qt5 commit: d4385e48b8566a5587048a3c6d8b2396ba587ed5 Task-number: QTBUG-21804 Change-Id: I81a82ed56bb0e4c0229fd117784790e1234aacca Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qlistview/tst_qlistview.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/auto/qlistview/tst_qlistview.cpp b/tests/auto/qlistview/tst_qlistview.cpp
index 5623ecb..a97296f 100644
--- a/tests/auto/qlistview/tst_qlistview.cpp
+++ b/tests/auto/qlistview/tst_qlistview.cpp
@@ -130,6 +130,8 @@ private slots:
void taskQTBUG_12308_wrongFlowLayout();
void taskQTBUG_21115_scrollToAndHiddenItems_data();
void taskQTBUG_21115_scrollToAndHiddenItems();
+ void taskQTBUG_21804_hiddenItemsAndScrollingWithKeys_data();
+ void taskQTBUG_21804_hiddenItemsAndScrollingWithKeys();
};
// Testing get/set functions
@@ -2108,5 +2110,55 @@ void tst_QListView::taskQTBUG_21115_scrollToAndHiddenItems()
QCOMPARE(lv.visualRect(index), firstItemRect);
}
+void tst_QListView::taskQTBUG_21804_hiddenItemsAndScrollingWithKeys_data()
+{
+ QTest::addColumn<int>("flow");
+ QTest::newRow("flow TopToBottom") << static_cast<int>(QListView::TopToBottom);
+ QTest::newRow("flow LeftToRight") << static_cast<int>(QListView::LeftToRight);
+}
+
+void tst_QListView::taskQTBUG_21804_hiddenItemsAndScrollingWithKeys()
+{
+ QFETCH(int, flow);
+
+ // create some items to show
+ QStringListModel model;
+ QStringList list;
+ for (int i = 0; i < 60; i++)
+ list << QString::number(i);
+ model.setStringList(list);
+
+ // create listview
+ QListView lv;
+ lv.setFlow(static_cast<QListView::Flow>(flow));
+ lv.setModel(&model);
+ lv.show();
+ QTest::qWaitForWindowShown(&lv);
+
+ // hide every odd number row
+ for (int i = 1; i < model.rowCount(); i+=2)
+ lv.setRowHidden(i, true);
+
+ // scroll forward and check that selected item is visible always
+ for (int i = 0; i < model.rowCount()/2; i++) {
+ if (flow == QListView::TopToBottom)
+ QTest::keyClick(&lv, Qt::Key_Down);
+ else
+ QTest::keyClick(&lv, Qt::Key_Right);
+ QTest::qWait(100);
+ QVERIFY(lv.rect().contains(lv.visualRect(lv.currentIndex())));
+ }
+
+ // scroll backward
+ for (int i = 0; i < model.rowCount()/2; i++) {
+ if (flow == QListView::TopToBottom)
+ QTest::keyClick(&lv, Qt::Key_Up);
+ else
+ QTest::keyClick(&lv, Qt::Key_Left);
+ QTest::qWait(100);
+ QVERIFY(lv.rect().contains(lv.visualRect(lv.currentIndex())));
+ }
+}
+
QTEST_MAIN(tst_QListView)
#include "tst_qlistview.moc"