aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quick/items/qquicktableview.cpp2
-rw-r--r--tests/auto/quick/qquicktableview/data/tableviewfocus.qml6
-rw-r--r--tests/auto/quick/qquicktableview/tst_qquicktableview.cpp30
3 files changed, 26 insertions, 12 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp
index 1b4855e495..ffd0ff4fa5 100644
--- a/src/quick/items/qquicktableview.cpp
+++ b/src/quick/items/qquicktableview.cpp
@@ -770,7 +770,7 @@ void QQuickTableViewPrivate::releaseItem(FxTableItem *fxTableItem, QQmlTableInst
// If the item (or a descendant) has focus, remove it, so
// that the item doesn't enter with focus when it's reused.
const auto focusItem = static_cast<QQuickItem *>(window->focusObject());
- const bool hasFocus = item->isAncestorOf(focusItem);
+ const bool hasFocus = item == focusItem || item->isAncestorOf(focusItem);
if (hasFocus) {
const auto focusChild = QQuickItemPrivate::get(q)->subFocusItem;
QQuickWindowPrivate::get(window)->clearFocusInScope(q, focusChild, Qt::OtherFocusReason);
diff --git a/tests/auto/quick/qquicktableview/data/tableviewfocus.qml b/tests/auto/quick/qquicktableview/data/tableviewfocus.qml
index 35f9c06587..c388e2c8de 100644
--- a/tests/auto/quick/qquicktableview/data/tableviewfocus.qml
+++ b/tests/auto/quick/qquicktableview/data/tableviewfocus.qml
@@ -57,9 +57,13 @@ Item {
Component {
id: tableViewDelegate
Item {
+ id: delegate
implicitWidth: 100
implicitHeight: 50
- property alias textInput: textInput
+ focus: true
+
+ property alias delegateRoot: delegate
+ property alias delegateChild: textInput
TextInput {
id: textInput
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
index 580500e787..6a6849eeae 100644
--- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
+++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
@@ -109,8 +109,9 @@ private slots:
void countDelegateItems();
void checkLayoutOfEqualSizedDelegateItems_data();
void checkLayoutOfEqualSizedDelegateItems();
- void checkTableMargins_data();
+ void checkFocusRemoved_data();
void checkFocusRemoved();
+ void checkTableMargins_data();
void checkTableMargins();
void fillTableViewButNothingMore_data();
void fillTableViewButNothingMore();
@@ -738,27 +739,36 @@ void tst_QQuickTableView::checkLayoutOfEqualSizedDelegateItems()
}
}
+void tst_QQuickTableView::checkFocusRemoved_data()
+{
+ QTest::addColumn<QString>("focusedItemProp");
+
+ QTest::newRow("delegate root") << QStringLiteral("delegateRoot");
+ QTest::newRow("delegate child") << QStringLiteral("delegateChild");
+}
+
void tst_QQuickTableView::checkFocusRemoved()
{
// Check that we clear the focus of a delegate item when
- // it's flicked out of view, and then reused.
+ // a child of the delegate item has focus, and the cell is
+ // flicked out of view.
+ QFETCH(QString, focusedItemProp);
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);
+ auto const focusedItem = qvariant_cast<QQuickItem *>(item->property(focusedItemProp.toUtf8().data()));
+ QVERIFY(focusedItem);
QCOMPARE(tableView->hasActiveFocus(), false);
- QCOMPARE(textInput->hasActiveFocus(), false);
+ QCOMPARE(focusedItem->hasActiveFocus(), false);
- textInput->forceActiveFocus();
+ focusedItem->forceActiveFocus();
QCOMPARE(tableView->hasActiveFocus(), true);
- QCOMPARE(textInput->hasActiveFocus(), true);
+ QCOMPARE(focusedItem->hasActiveFocus(), true);
// Flick the focused cell out, and check that none of the
// items in the table has focus (which means that the reused
@@ -767,8 +777,8 @@ void tst_QQuickTableView::checkFocusRemoved()
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);
+ auto const focusedItem2 = qvariant_cast<QQuickItem *>(fxItem->item->property(focusedItemProp.toUtf8().data()));
+ QCOMPARE(focusedItem2->hasActiveFocus(), false);
}
}