From 2431853d824c6416f2cb760485df5cb4c27db7e5 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 27 Mar 2019 16:23:24 +0100 Subject: SpinBox: fix indicators being hovered when mouse is moved while pressed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We also need to update the hovered state of each indicator when the mouse is moved while pressed, not just when we get hover move events. Change-Id: I6fa71344fd540f648683958e5804ae735523e72d Fixes: QTBUG-74688 Reviewed-by: Henning Gründl Reviewed-by: Frederik Gladhorn --- src/quicktemplates2/qquickspinbox.cpp | 6 ++++-- tests/auto/controls/data/tst_spinbox.qml | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/quicktemplates2/qquickspinbox.cpp b/src/quicktemplates2/qquickspinbox.cpp index 6af1d8e8..274929b0 100644 --- a/src/quicktemplates2/qquickspinbox.cpp +++ b/src/quicktemplates2/qquickspinbox.cpp @@ -362,8 +362,10 @@ void QQuickSpinBoxPrivate::handleMove(const QPointF &point) QQuickControlPrivate::handleMove(point); QQuickItem *ui = up->indicator(); QQuickItem *di = down->indicator(); - up->setPressed(ui && ui->isEnabled() && ui->contains(ui->mapFromItem(q, point))); - down->setPressed(di && di->isEnabled() && di->contains(di->mapFromItem(q, point))); + up->setHovered(ui && ui->isEnabled() && ui->contains(ui->mapFromItem(q, point))); + up->setPressed(up->isHovered()); + down->setHovered(di && di->isEnabled() && di->contains(di->mapFromItem(q, point))); + down->setPressed(down->isHovered()); bool pressed = up->isPressed() || down->isPressed(); q->setAccessibleProperty("pressed", pressed); diff --git a/tests/auto/controls/data/tst_spinbox.qml b/tests/auto/controls/data/tst_spinbox.qml index 419478a2..d3a0d8bb 100644 --- a/tests/auto/controls/data/tst_spinbox.qml +++ b/tests/auto/controls/data/tst_spinbox.qml @@ -486,6 +486,39 @@ TestCase { compare(button.hovered, false) } + function test_hoverWhilePressed_data() { + return [ + { tag: "up" }, + { tag: "down" }, + ] + } + + // QTBUG-74688 + function test_hoverWhilePressed(data) { + var control = createTemporaryObject(spinBox, testCase, { hoverEnabled: true, value: 50 }) + verify(control) + + var button = control[data.tag] + compare(control.hovered, false) + compare(button.hovered, false) + + // Hover over the indicator. It should be hovered. + var buttonXCenter = button.indicator.x + button.indicator.width / 2 + var buttonYCenter = button.indicator.y + button.indicator.height / 2 + mouseMove(control, buttonXCenter, buttonYCenter) + compare(button.hovered, true) + + // Press on the indicator and then move the mouse outside of it. + mousePress(control, buttonXCenter, buttonYCenter) + compare(button.hovered, true) + mouseMove(control, buttonXCenter - button.indicator.width, buttonYCenter - button.indicator.height) + // It should not be pressed or hovered. + compare(button.pressed, false) + compare(button.hovered, false) + + mouseRelease(control) + } + function test_valueFromText_data() { return [ { tag: "editable", editable: true }, -- cgit v1.2.3 From 8349cf8335ca16c7ecc85e877d9f4ec24bad49cd Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Mon, 8 Apr 2019 13:32:12 +0200 Subject: Doc: add a Size section to explain StackView's sizing behavior Task-number: QTBUG-74902 Change-Id: I3f77459028de48729bb78353d8d95e92c7fc98f6 Reviewed-by: Paul Wicking --- src/quicktemplates2/qquickstackview.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/quicktemplates2/qquickstackview.cpp b/src/quicktemplates2/qquickstackview.cpp index 6dae65c8..18f65127 100644 --- a/src/quicktemplates2/qquickstackview.cpp +++ b/src/quicktemplates2/qquickstackview.cpp @@ -343,6 +343,35 @@ QT_BEGIN_NAMESPACE } \endqml + \section1 Size + + StackView does not inherit an implicit size from items that are pushed onto + it. This means that using it as the \l {Popup::}{contentItem} of a + \l Dialog, for example, will not work as expected: + + \code + Dialog { + StackView { + initialItem: Rectangle { + width: 200 + height: 200 + color: "salmon" + } + } + } + \endcode + + There are several ways to ensure that StackView has a size in this + situation: + + \list + \li Set \l implicitWidth and \l implicitHeight on the StackView itself. + \li Set \l implicitWidth and \l implicitHeight on the \l Rectangle. + \li Set \l {Popup::}{contentWidth} and \l {Popup::}{contentHeight} on + the Dialog. + \li Give the Dialog a size. + \endlist + \sa {Customizing StackView}, {Navigation Controls}, {Container Controls}, {Focus Management in Qt Quick Controls 2} */ -- cgit v1.2.3 From f5f36b0db64e77822ef3053245c993ed14949192 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Mon, 8 Apr 2019 14:18:28 +0200 Subject: Doc: expand upon Pane's Content Sizing section Mention what happens if its contentItem has no implicit size and only one child item. Change-Id: I646ca2baad89ac195836268b14108b43beaec2bf Fixes: QTBUG-69096 Reviewed-by: Paul Wicking --- src/quicktemplates2/qquickpane.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/quicktemplates2/qquickpane.cpp b/src/quicktemplates2/qquickpane.cpp index 3edbce9d..fd9d2cf0 100644 --- a/src/quicktemplates2/qquickpane.cpp +++ b/src/quicktemplates2/qquickpane.cpp @@ -103,6 +103,22 @@ QT_BEGIN_NAMESPACE } \endcode + If the \l contentItem has no implicit size and only one child, Pane will + use the implicit size of that child. For example, in the following code, + the Pane will assume the size of the Rectangle: + + \code + Pane { + Item { + Rectangle { + implicitWidth: 200 + implicitHeight: 200 + color: "salmon" + } + } + } + \endcode + \sa {Customizing Pane}, {Container Controls}, {Focus Management in Qt Quick Controls 2}, {Event Handling} */ -- cgit v1.2.3 From bd126fdea95ed994fdd35d50e445b45af75657ab Mon Sep 17 00:00:00 2001 From: Alberto Mardegan Date: Sun, 24 Mar 2019 22:54:31 +0300 Subject: QQuickComboBox: don't hide popup if focused The ComboBox popup should be closed when the ComboBox loses focus, but not if the control gaining focus is the popup itself. While all the styles implemented in this module implement the ComboBox popup as an unfocusable window and handle all the keyboard events in QQuickComboBox itself, the developer can choose to replace the popup with a custom implementation, which might need the keyboard focus. Fixes: QTBUG-74661 Change-Id: I838ab9cb697df63ea2099e68f1ae99eadb06be08 Reviewed-by: Richard Moe Gustavsen --- src/quicktemplates2/qquickcombobox.cpp | 10 +++--- tests/auto/controls/data/tst_combobox.qml | 51 +++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/quicktemplates2/qquickcombobox.cpp b/src/quicktemplates2/qquickcombobox.cpp index 03dd6086..328797b8 100644 --- a/src/quicktemplates2/qquickcombobox.cpp +++ b/src/quicktemplates2/qquickcombobox.cpp @@ -1556,10 +1556,10 @@ bool QQuickComboBox::eventFilter(QObject *object, QEvent *event) break; } case QEvent::FocusOut: - if (qGuiApp->focusObject() != this) { + if (qGuiApp->focusObject() != this && (!d->popup || !d->popup->hasActiveFocus())) { // Only close the popup if focus was transferred somewhere else - // than to the popup button (which normally means that the user - // clicked on the popup button to open it, not close it. + // than to the popup or the popup button (which normally means that + // the user clicked on the popup button to open it, not close it). d->hidePopup(false); setPressed(false); } @@ -1589,9 +1589,9 @@ void QQuickComboBox::focusOutEvent(QFocusEvent *event) Q_D(QQuickComboBox); QQuickControl::focusOutEvent(event); - if (qGuiApp->focusObject() != d->contentItem) { + if (qGuiApp->focusObject() != d->contentItem && (!d->popup || !d->popup->hasActiveFocus())) { // Only close the popup if focus was transferred - // somewhere else than to the inner line edit (which is + // somewhere else than to the popup or the inner line edit (which is // normally done from QQuickComboBox::focusInEvent). d->hidePopup(false); setPressed(false); diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml index 70c4f090..0d266e1a 100644 --- a/tests/auto/controls/data/tst_combobox.qml +++ b/tests/auto/controls/data/tst_combobox.qml @@ -85,6 +85,17 @@ TestCase { MouseArea { } } + Component { + id: customPopup + Popup { + width: 100 + implicitHeight: contentItem.implicitHeight + contentItem: TextInput { + anchors.fill: parent + } + } + } + function init() { // QTBUG-61225: Move the mouse away to avoid QQuickWindowPrivate::flushFrameSynchronousEvents() // delivering interfering hover events based on the last mouse position from earlier tests. For @@ -1680,4 +1691,44 @@ TestCase { compare(container.releasedKeys, ++releasedKeys) compare(container.lastReleasedKey, data.key) } + + function test_popupFocus_QTBUG_74661() { + var control = createTemporaryObject(comboBox, testCase) + verify(control) + + var popup = createTemporaryObject(customPopup, testCase) + verify(popup) + + control.popup = popup + + var openedSpy = signalSpy.createObject(control, {target: popup, signalName: "opened"}) + verify(openedSpy.valid) + + var closedSpy = signalSpy.createObject(control, {target: popup, signalName: "closed"}) + verify(closedSpy.valid) + + control.forceActiveFocus() + verify(control.activeFocus) + + // show popup + keyClick(Qt.Key_Space) + openedSpy.wait() + compare(openedSpy.count, 1) + + popup.contentItem.forceActiveFocus() + verify(popup.contentItem.activeFocus) + + // type something in the text field + keyClick(Qt.Key_Space) + keyClick(Qt.Key_H) + keyClick(Qt.Key_I) + compare(popup.contentItem.text, " hi") + + compare(closedSpy.count, 0) + + // hide popup + keyClick(Qt.Key_Escape) + closedSpy.wait() + compare(closedSpy.count, 1) + } } -- cgit v1.2.3 From 0bf12eda7c5863bf3b22306f501292a9c6f2aa16 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Thu, 11 Apr 2019 12:26:43 +0200 Subject: Update plugins.qmltypes for QtQuick.Controls This amends 1693a19fd557c857ef4f43ab303ea1056790481e Change-Id: I70ef68de56405eb705d1c79be4eed8925def319a Reviewed-by: Mitch Curtis --- src/imports/controls/controls.pro | 2 +- src/imports/controls/plugins.qmltypes | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/imports/controls/controls.pro b/src/imports/controls/controls.pro index db0d14ae..2aeaf9ab 100644 --- a/src/imports/controls/controls.pro +++ b/src/imports/controls/controls.pro @@ -1,6 +1,6 @@ TARGET = qtquickcontrols2plugin TARGETPATH = QtQuick/Controls.2 -IMPORT_VERSION = 2.5 +IMPORT_VERSION = 2.$$QT_MINOR_VERSION QT += qml quick QT_PRIVATE += core-private gui-private qml-private quick-private quicktemplates2-private quickcontrols2-private diff --git a/src/imports/controls/plugins.qmltypes b/src/imports/controls/plugins.qmltypes index 26f0251c..9b4610f0 100644 --- a/src/imports/controls/plugins.qmltypes +++ b/src/imports/controls/plugins.qmltypes @@ -4,7 +4,7 @@ import QtQuick.tooling 1.2 // It is used for QML tooling purposes only. // // This file was auto-generated by: -// 'qmlplugindump -nonrelocatable -dependencies dependencies.json QtQuick.Controls 2.5' +// 'qmlplugindump -nonrelocatable -dependencies dependencies.json QtQuick.Controls 2.13' Module { dependencies: [ -- cgit v1.2.3 From 131210b59133fcebe0ab3c7823777f2b859dc7cd Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Thu, 11 Apr 2019 12:52:36 +0200 Subject: Update plugins.qmltypes for QtQuick.Templates This amends 1693a19fd557c857ef4f43ab303ea1056790481e Change-Id: I1c23d8a859e2cc2b878ddf2b6e7df35755abde22 Reviewed-by: Mitch Curtis --- src/imports/templates/plugins.qmltypes | 3 +-- src/imports/templates/templates.pro | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/imports/templates/plugins.qmltypes b/src/imports/templates/plugins.qmltypes index 0922e871..48e23edd 100644 --- a/src/imports/templates/plugins.qmltypes +++ b/src/imports/templates/plugins.qmltypes @@ -4,7 +4,7 @@ import QtQuick.tooling 1.2 // It is used for QML tooling purposes only. // // This file was auto-generated by: -// 'qmlplugindump -nonrelocatable -dependencies dependencies.json QtQuick.Templates 2.5' +// 'qmlplugindump -nonrelocatable -dependencies dependencies.json QtQuick.Templates 2.13' Module { dependencies: ["QtQuick 2.9", "QtQuick.Window 2.2"] @@ -1065,7 +1065,6 @@ Module { prototype: "QObject" Property { name: "centerIn"; type: "QQuickItem"; isPointer: true } } - Component { name: "QQuickPopupItem"; defaultProperty: "contentData"; prototype: "QQuickPage" } Component { name: "QQuickProgressBar" defaultProperty: "data" diff --git a/src/imports/templates/templates.pro b/src/imports/templates/templates.pro index b132f47d..3447ef90 100644 --- a/src/imports/templates/templates.pro +++ b/src/imports/templates/templates.pro @@ -1,6 +1,6 @@ TARGET = qtquicktemplates2plugin TARGETPATH = QtQuick/Templates.2 -IMPORT_VERSION = 2.5 +IMPORT_VERSION = 2.$$QT_MINOR_VERSION QT += qml quick QT_PRIVATE += core-private gui-private qml-private quick-private quicktemplates2-private -- cgit v1.2.3