aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-09-05 13:45:38 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-09-06 13:08:16 +0000
commit34c987cbd10971e4b5a00d08c6061b2f65967e56 (patch)
treea4fee67fea1e2715eca845807790c69797e88445 /tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
parent77aefc95cf3fbae342004513fd8c9f3a0184eba9 (diff)
QQuickTableView: clear focus when delegate item with focus is flicked out
If we flick out a cell that has keyboard focus, we should clear that focus. Otherwise, the item will be focused also when it is later reused. Change-Id: I0fb79b6d906c1907a352de4ec52e3b488064b55a Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/quick/qquicktableview/tst_qquicktableview.cpp')
-rw-r--r--tests/auto/quick/qquicktableview/tst_qquicktableview.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
index 45b3566574..580500e787 100644
--- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
+++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
@@ -110,6 +110,7 @@ private slots:
void checkLayoutOfEqualSizedDelegateItems_data();
void checkLayoutOfEqualSizedDelegateItems();
void checkTableMargins_data();
+ void checkFocusRemoved();
void checkTableMargins();
void fillTableViewButNothingMore_data();
void fillTableViewButNothingMore();
@@ -737,6 +738,40 @@ void tst_QQuickTableView::checkLayoutOfEqualSizedDelegateItems()
}
}
+void tst_QQuickTableView::checkFocusRemoved()
+{
+ // Check that we clear the focus of a delegate item when
+ // it's flicked out of view, and then reused.
+ LOAD_TABLEVIEW("tableviewfocus.qml");
+
+ const char *textInputProp = "textInput";
+ auto model = TestModelAsVariant(100, 100);
+ tableView->setModel(model);
+
+ WAIT_UNTIL_POLISHED;
+
+ auto const item = tableViewPrivate->loadedTableItem(QPoint(0, 0))->item;
+ auto const textInput = qvariant_cast<QQuickItem *>(item->property(textInputProp));
+ QVERIFY(textInput);
+ QCOMPARE(tableView->hasActiveFocus(), false);
+ QCOMPARE(textInput->hasActiveFocus(), false);
+
+ textInput->forceActiveFocus();
+ QCOMPARE(tableView->hasActiveFocus(), true);
+ QCOMPARE(textInput->hasActiveFocus(), true);
+
+ // Flick the focused cell out, and check that none of the
+ // items in the table has focus (which means that the reused
+ // item lost focus when it was flicked out). But the tableview
+ // itself will maintain active focus.
+ tableView->setContentX(500);
+ QCOMPARE(tableView->hasActiveFocus(), true);
+ for (auto fxItem : tableViewPrivate->loadedItems) {
+ auto const textInput2 = qvariant_cast<QQuickItem *>(fxItem->item->property(textInputProp));
+ QCOMPARE(textInput2->hasActiveFocus(), false);
+ }
+}
+
void tst_QQuickTableView::checkTableMargins_data()
{
QTest::addColumn<QVariant>("model");