From e60d8a28034550ae08b258494726050ea9638602 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 22 Jan 2014 14:25:48 +0100 Subject: If a popup window is opened, do not change the focus It's not working to have QQuickWindow lose focus every time a menu is opened. This doesn't happen on OSX because menus are implemented as special native ones, but on X11 a menu is another window. In QtQuick Controls it's useful for copy/cut/paste Actions to be enabled based on whether some text has focus. Change-Id: I092b46133b9a8a44639ad9d89ee2bdfe30206bd9 Task-number: QTBUG-36292 Task-number: QTBUG-36332 Reviewed-by: Gabriel de Dietrich --- src/quick/items/qquickitem.cpp | 10 ++++++---- tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp | 2 +- tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index 6afdc69291..3f0dae8070 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -6391,10 +6391,12 @@ void QQuickItem::setFocus(bool focus, Qt::FocusReason reason) while (scope && !scope->isFocusScope() && scope->parentItem()) scope = scope->parentItem(); if (d->window) { - if (focus) - QQuickWindowPrivate::get(d->window)->setFocusInScope(scope, this, reason); - else - QQuickWindowPrivate::get(d->window)->clearFocusInScope(scope, this, reason); + if (reason != Qt::PopupFocusReason) { + if (focus) + QQuickWindowPrivate::get(d->window)->setFocusInScope(scope, this, reason); + else + QQuickWindowPrivate::get(d->window)->clearFocusInScope(scope, this, reason); + } } else { // do the focus changes from setFocusInScope/clearFocusInScope that are // unrelated to a window diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index 91a6886bf0..45d23abbf6 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -1296,7 +1296,7 @@ void tst_qquicktextedit::selectionOnFocusOut() QVERIFY(edit2->hasActiveFocus()); edit2->setFocus(false, Qt::PopupFocusReason); - QVERIFY(!edit2->hasActiveFocus()); + QVERIFY(edit2->hasActiveFocus()); QCOMPARE(edit2->selectedText(), QLatin1String("text 2")); } diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index 273c0de660..e125c33a56 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -3605,7 +3605,8 @@ void tst_qquicktextinput::focusOutNotClearSelection() input.setFocus(false, Qt::PopupFocusReason); QGuiApplication::processEvents(); QTRY_COMPARE(input.selectedText(), QLatin1String("llo")); - QTRY_COMPARE(input.hasActiveFocus(), false); + // QTBUG-36332 and 36292: a popup window does not take focus + QTRY_COMPARE(input.hasActiveFocus(), true); input.setFocus(true); QTRY_COMPARE(input.hasActiveFocus(), true); -- cgit v1.2.3