1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include <qtest.h>
30#include <QtTest/QSignalSpy>
31#include <QtQml/qqmlengine.h>
32#include <QtQml/qqmlcomponent.h>
33#include <QtQml/qqmlcontext.h>
34#include <QtQuick/qquickview.h>
35#include <QtQuick/private/qquickitem_p.h>
36#include <QtGui/private/qguiapplication_p.h>
37#include <QtGui/qstylehints.h>
38#include "../shared/util.h"
39#include "../shared/visualtestutil.h"
40
41using namespace QQuickVisualTestUtil;
42
43class tst_activeFocusOnTab : public QQmlDataTest
44{
45 Q_OBJECT
46public:
47 tst_activeFocusOnTab();
48
49private slots:
50 void initTestCase();
51 void cleanup();
52
53 void activeFocusOnTab();
54 void activeFocusOnTab2();
55private:
56 QQmlEngine engine;
57 bool qt_tab_all_widgets() {
58 return QGuiApplication::styleHints()->tabFocusBehavior() == Qt::TabFocusAllControls;
59 }
60};
61
62tst_activeFocusOnTab::tst_activeFocusOnTab()
63{
64}
65
66void tst_activeFocusOnTab::initTestCase()
67{
68 QQmlDataTest::initTestCase();
69}
70
71void tst_activeFocusOnTab::cleanup()
72{
73}
74
75void tst_activeFocusOnTab::activeFocusOnTab()
76{
77 if (!qt_tab_all_widgets())
78 QSKIP("This function doesn't support NOT iterating all.");
79
80 QQuickView *window = new QQuickView(0);
81 window->setBaseSize(QSize(800,600));
82
83 window->setSource(testFileUrl(fileName: "activeFocusOnTab.qml"));
84 window->show();
85 window->requestActivate();
86 QVERIFY(QTest::qWaitForWindowActive(window));
87 QVERIFY(QGuiApplication::focusWindow() == window);
88
89 // original: button1
90 QQuickItem *item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "button1");
91 QVERIFY(item);
92 QVERIFY(item->hasActiveFocus());
93
94 // Tab: button1->button2
95 QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
96 QGuiApplication::sendEvent(receiver: window, event: &key);
97 QVERIFY(key.isAccepted());
98
99 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "button2");
100 QVERIFY(item);
101 QVERIFY(item->hasActiveFocus());
102
103 // Tab: button2->toolbutton
104 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
105 QGuiApplication::sendEvent(receiver: window, event: &key);
106 QVERIFY(key.isAccepted());
107
108 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "toolbutton");
109 QVERIFY(item);
110 QVERIFY(item->hasActiveFocus());
111
112 // Tab: toolbutton->combobox
113 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
114 QGuiApplication::sendEvent(receiver: window, event: &key);
115 QVERIFY(key.isAccepted());
116
117 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "combobox");
118 QVERIFY(item);
119 QVERIFY(item->hasActiveFocus());
120
121 // Tab: combobox->editable_combobox
122 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
123 QGuiApplication::sendEvent(receiver: window, event: &key);
124 QVERIFY(key.isAccepted());
125
126 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "editable_combobox");
127 QVERIFY(item);
128 QVERIFY(item->hasActiveFocus());
129
130 // Tab: editable_combobox->group1_checkbox
131 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
132 QGuiApplication::sendEvent(receiver: window, event: &key);
133 QVERIFY(key.isAccepted());
134
135 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "group1");
136 QVERIFY(item);
137 QQuickItem *subitem = findItem<QQuickItem>(parent: item, objectName: "group1_checkbox");
138 QVERIFY(subitem);
139 QVERIFY(subitem->hasActiveFocus());
140
141 // Tab: group1->checkbox1
142 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
143 QGuiApplication::sendEvent(receiver: window, event: &key);
144 QVERIFY(key.isAccepted());
145
146 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "checkbox1");
147 QVERIFY(item);
148 QVERIFY(item->hasActiveFocus());
149
150 // Tab: checkbox1->checkbox2
151 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
152 QGuiApplication::sendEvent(receiver: window, event: &key);
153 QVERIFY(key.isAccepted());
154
155 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "checkbox2");
156 QVERIFY(item);
157 QVERIFY(item->hasActiveFocus());
158
159 // Tab: checkbox2->radiobutton1
160 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
161 QGuiApplication::sendEvent(receiver: window, event: &key);
162 QVERIFY(key.isAccepted());
163
164 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "radiobutton1");
165 QVERIFY(item);
166 QVERIFY(item->hasActiveFocus());
167
168 // Tab: radiobutton1->radiobutton2
169 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
170 QGuiApplication::sendEvent(receiver: window, event: &key);
171 QVERIFY(key.isAccepted());
172
173 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "radiobutton2");
174 QVERIFY(item);
175 QVERIFY(item->hasActiveFocus());
176
177 // Tab: radiobutton2->slider
178 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
179 QGuiApplication::sendEvent(receiver: window, event: &key);
180 QVERIFY(key.isAccepted());
181
182 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "slider");
183 QVERIFY(item);
184 QVERIFY(item->hasActiveFocus());
185
186 // Tab: slider->spinbox
187 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
188 QGuiApplication::sendEvent(receiver: window, event: &key);
189 QVERIFY(key.isAccepted());
190
191 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "spinbox");
192 QVERIFY(item);
193 QVERIFY(item->hasActiveFocus());
194
195 // Tab: spinbox->tab1_btn1
196 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
197 for (int i = 0; i < 2; ++i) {
198 QGuiApplication::sendEvent(receiver: window, event: &key);
199 QVERIFY(key.isAccepted());
200 }
201
202 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "tab1_btn1");
203 QVERIFY(item);
204 QVERIFY(item->hasActiveFocus());
205
206 // Tab: tab1_btn1->tab1_btn2
207 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
208 QGuiApplication::sendEvent(receiver: window, event: &key);
209 QVERIFY(key.isAccepted());
210
211 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "tab1_btn2");
212 QVERIFY(item);
213 QVERIFY(item->hasActiveFocus());
214
215 // Tab: tab1_btn2->textfield
216 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
217 QGuiApplication::sendEvent(receiver: window, event: &key);
218 QVERIFY(key.isAccepted());
219
220 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "textfield");
221 QVERIFY(item);
222 QVERIFY(item->hasActiveFocus());
223
224 // Tab: textfield->tableview
225 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
226 QGuiApplication::sendEvent(receiver: window, event: &key);
227 QVERIFY(key.isAccepted());
228
229 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "tableview");
230 QVERIFY(item);
231 QVERIFY(item->hasActiveFocus());
232
233 // Tab: tableview->textarea
234 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
235 QGuiApplication::sendEvent(receiver: window, event: &key);
236 QVERIFY(key.isAccepted());
237
238 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "textarea");
239 QVERIFY(item);
240 QVERIFY(item->hasActiveFocus());
241
242 // BackTab: textarea->tableview
243 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
244 QGuiApplication::sendEvent(receiver: window, event: &key);
245 QVERIFY(key.isAccepted());
246
247 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "tableview");
248 QVERIFY(item);
249 QVERIFY(item->hasActiveFocus());
250
251 // BackTab: tableview->textfield
252 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
253 QGuiApplication::sendEvent(receiver: window, event: &key);
254 QVERIFY(key.isAccepted());
255
256 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "textfield");
257 QVERIFY(item);
258 QVERIFY(item->hasActiveFocus());
259
260 // BackTab: textfield->tab1_btn2
261 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
262 QGuiApplication::sendEvent(receiver: window, event: &key);
263 QVERIFY(key.isAccepted());
264
265 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "tab1_btn2");
266 QVERIFY(item);
267 QVERIFY(item->hasActiveFocus());
268
269 // BackTab: tab1_btn2->tab1_btn1
270 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
271 QGuiApplication::sendEvent(receiver: window, event: &key);
272 QVERIFY(key.isAccepted());
273
274 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "tab1_btn1");
275 QVERIFY(item);
276 QVERIFY(item->hasActiveFocus());
277
278 // BackTab: tab1_btn1->tab1
279 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
280 QGuiApplication::sendEvent(receiver: window, event: &key);
281 QVERIFY(key.isAccepted());
282/*
283 // Right: tab1->tab2
284 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Right, Qt::NoModifier, "", false, 1);
285 QGuiApplication::sendEvent(window, &key);
286 QVERIFY(key.isAccepted());
287
288 // Tab: tab2->tab2_btn1
289 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
290 QGuiApplication::sendEvent(window, &key);
291 QVERIFY(key.isAccepted());
292
293 item = findItem<QQuickItem>(window->rootObject(), "tab2_btn1");
294 QVERIFY(item);
295 QVERIFY(item->hasActiveFocus());
296
297 // Tab: tab2_btn1->tab2_btn2
298 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
299 QGuiApplication::sendEvent(window, &key);
300 QVERIFY(key.isAccepted());
301
302 item = findItem<QQuickItem>(window->rootObject(), "tab2_btn2");
303 QVERIFY(item);
304 QVERIFY(item->hasActiveFocus());
305
306 // Tab: tab2_btn2->textfield
307 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
308 QGuiApplication::sendEvent(window, &key);
309 QVERIFY(key.isAccepted());
310
311 item = findItem<QQuickItem>(window->rootObject(), "textfield");
312 QVERIFY(item);
313 QVERIFY(item->hasActiveFocus());
314
315 // BackTab: textfield->tab2_btn2
316 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
317 QGuiApplication::sendEvent(window, &key);
318 QVERIFY(key.isAccepted());
319
320 item = findItem<QQuickItem>(window->rootObject(), "tab2_btn2");
321 QVERIFY(item);
322 QVERIFY(item->hasActiveFocus());
323
324 // BackTab: tab2_btn2->tab2_btn1
325 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
326 QGuiApplication::sendEvent(window, &key);
327 QVERIFY(key.isAccepted());
328
329 item = findItem<QQuickItem>(window->rootObject(), "tab2_btn1");
330 QVERIFY(item);
331 QVERIFY(item->hasActiveFocus());
332
333 // BackTab: tab2_btn1->tab2
334 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
335 QGuiApplication::sendEvent(window, &key);
336 QVERIFY(key.isAccepted());
337*/
338 // BackTab: tab2->spinbox
339 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
340 QGuiApplication::sendEvent(receiver: window, event: &key);
341 QVERIFY(key.isAccepted());
342
343 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "spinbox");
344 QVERIFY(item);
345 QVERIFY(item->hasActiveFocus());
346
347 // BackTab: spinbox->slider
348 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
349 QGuiApplication::sendEvent(receiver: window, event: &key);
350 QVERIFY(key.isAccepted());
351
352 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "slider");
353 QVERIFY(item);
354 QVERIFY(item->hasActiveFocus());
355
356 // BackTab: slider->radiobutton2
357 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
358 QGuiApplication::sendEvent(receiver: window, event: &key);
359 QVERIFY(key.isAccepted());
360
361 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "radiobutton2");
362 QVERIFY(item);
363 QVERIFY(item->hasActiveFocus());
364
365 // BackTab: radiobutton2->radiobutton1
366 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
367 QGuiApplication::sendEvent(receiver: window, event: &key);
368 QVERIFY(key.isAccepted());
369
370 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "radiobutton1");
371 QVERIFY(item);
372 QVERIFY(item->hasActiveFocus());
373
374 // BackTab: radiobutton1->checkbox2
375 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
376 QGuiApplication::sendEvent(receiver: window, event: &key);
377 QVERIFY(key.isAccepted());
378
379 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "checkbox2");
380 QVERIFY(item);
381 QVERIFY(item->hasActiveFocus());
382
383 // BackTab: checkbox2->checkbox1
384 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
385 QGuiApplication::sendEvent(receiver: window, event: &key);
386 QVERIFY(key.isAccepted());
387
388 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "checkbox1");
389 QVERIFY(item);
390 QVERIFY(item->hasActiveFocus());
391
392 // BackTab: checkbox1->group1_checkbox
393 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
394 QGuiApplication::sendEvent(receiver: window, event: &key);
395 QVERIFY(key.isAccepted());
396
397 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "group1_checkbox");
398 QVERIFY(item);
399 QVERIFY(item->hasActiveFocus());
400
401 // BackTab: group1_checkbox->editable_combobox
402 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
403 QGuiApplication::sendEvent(receiver: window, event: &key);
404 QVERIFY(key.isAccepted());
405
406 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "editable_combobox");
407 QVERIFY(item);
408 QVERIFY(item->hasActiveFocus());
409
410 // BackTab: editable_combobox->combobox
411 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
412 QGuiApplication::sendEvent(receiver: window, event: &key);
413 QVERIFY(key.isAccepted());
414
415 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "combobox");
416 QVERIFY(item);
417 QVERIFY(item->hasActiveFocus());
418
419 // BackTab: combobox->toolbutton
420 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
421 QGuiApplication::sendEvent(receiver: window, event: &key);
422 QVERIFY(key.isAccepted());
423
424 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "toolbutton");
425 QVERIFY(item);
426 QVERIFY(item->hasActiveFocus());
427
428 // BackTab: toolbutton->button2
429 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
430 QGuiApplication::sendEvent(receiver: window, event: &key);
431 QVERIFY(key.isAccepted());
432
433 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "button2");
434 QVERIFY(item);
435 QVERIFY(item->hasActiveFocus());
436
437 // BackTab: button2->button1
438 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
439 QGuiApplication::sendEvent(receiver: window, event: &key);
440 QVERIFY(key.isAccepted());
441
442 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "button1");
443 QVERIFY(item);
444 QVERIFY(item->hasActiveFocus());
445
446 // BackTab: button1->textarea
447 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
448 QGuiApplication::sendEvent(receiver: window, event: &key);
449 QVERIFY(key.isAccepted());
450
451 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "textarea");
452 QVERIFY(item);
453 QVERIFY(item->hasActiveFocus());
454
455 delete window;
456}
457
458void tst_activeFocusOnTab::activeFocusOnTab2()
459{
460 if (qt_tab_all_widgets())
461 QSKIP("This function doesn't support iterating all.");
462
463 QQuickView *window = new QQuickView(0);
464 window->setBaseSize(QSize(800,600));
465
466 window->setSource(testFileUrl(fileName: "activeFocusOnTab.qml"));
467 window->show();
468 window->requestActivate();
469 QVERIFY(QTest::qWaitForWindowActive(window));
470 QVERIFY(QGuiApplication::focusWindow() == window);
471
472 // original: editable_combobox
473 QQuickItem *item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "editable_combobox");
474 QVERIFY(item);
475 item->forceActiveFocus();
476 QVERIFY(item->hasActiveFocus());
477
478 // Tab: editable_combobox->spinbox
479 QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
480 QGuiApplication::sendEvent(receiver: window, event: &key);
481 QVERIFY(key.isAccepted());
482
483 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "spinbox");
484 QVERIFY(item);
485 QVERIFY(item->hasActiveFocus());
486
487 // Tab: spinbox->textfield
488 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
489 QGuiApplication::sendEvent(receiver: window, event: &key);
490 QVERIFY(key.isAccepted());
491
492 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "textfield");
493 QVERIFY(item);
494 QVERIFY(item->hasActiveFocus());
495
496 // Tab: textfield->tableview
497 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
498 QGuiApplication::sendEvent(receiver: window, event: &key);
499 QVERIFY(key.isAccepted());
500
501 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "tableview");
502 QVERIFY(item);
503 QVERIFY(item->hasActiveFocus());
504
505 // Tab: tableview->textarea
506 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1);
507 QGuiApplication::sendEvent(receiver: window, event: &key);
508 QVERIFY(key.isAccepted());
509
510 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "textarea");
511 QVERIFY(item);
512 QVERIFY(item->hasActiveFocus());
513
514 // BackTab: textarea->tableview
515 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
516 QGuiApplication::sendEvent(receiver: window, event: &key);
517 QVERIFY(key.isAccepted());
518
519 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "tableview");
520 QVERIFY(item);
521 QVERIFY(item->hasActiveFocus());
522
523 // BackTab: tableview->textfield
524 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
525 QGuiApplication::sendEvent(receiver: window, event: &key);
526 QVERIFY(key.isAccepted());
527
528 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "textfield");
529 QVERIFY(item);
530 QVERIFY(item->hasActiveFocus());
531
532 // BackTab: textfield->spinbox
533 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
534 QGuiApplication::sendEvent(receiver: window, event: &key);
535 QVERIFY(key.isAccepted());
536
537 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "spinbox");
538 QVERIFY(item);
539 QVERIFY(item->hasActiveFocus());
540
541 // BackTab: spinbox->editable_combobox
542 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
543 QGuiApplication::sendEvent(receiver: window, event: &key);
544 QVERIFY(key.isAccepted());
545
546 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "editable_combobox");
547 QVERIFY(item);
548 QVERIFY(item->hasActiveFocus());
549
550 // BackTab: editable_combobox->textarea
551 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
552 QGuiApplication::sendEvent(receiver: window, event: &key);
553 QVERIFY(key.isAccepted());
554
555 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "textarea");
556 QVERIFY(item);
557 QVERIFY(item->hasActiveFocus());
558
559 // BackTab: textarea->tableview
560 key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1);
561 QGuiApplication::sendEvent(receiver: window, event: &key);
562 QVERIFY(key.isAccepted());
563
564 item = findItem<QQuickItem>(parent: window->rootObject(), objectName: "tableview");
565 QVERIFY(item);
566 QVERIFY(item->hasActiveFocus());
567
568 delete window;
569}
570
571QTEST_MAIN(tst_activeFocusOnTab)
572
573#include "tst_activeFocusOnTab.moc"
574

source code of qtquickcontrols/tests/auto/activeFocusOnTab/tst_activeFocusOnTab.cpp