aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2017-11-02 18:55:26 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2017-11-03 10:37:26 +0000
commita2d1f1ad14ca5e1123abe07329a28500ce71678d (patch)
tree8113e4f29c92f1d00c737a89d22f35c0f1966c3c
parentfbb5e0310687f8c628dc6e82a5f8b80fcd972f60 (diff)
QQuickTextField: retain selection on right mouse button click
QQuickTextField wants to emit pressed(), released(), and pressAndHold() signals not only on left, but on all mouse button clicks. Therefore it explicitly sets accepted mouse buttons to all. However, the base class, QQuickTextInput, has only been prepared to handle left (selection) and middle (paste) mouse buttons. Don't pass right mouse button -only events to the base class to avoid it clearing selection on right click. Task-number: QTBUG-64048 Change-Id: I015820c78995cc8dd7cbeb16fca0f9b991040bad Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/quicktemplates2/qquicktextfield.cpp12
-rw-r--r--tests/auto/controls/data/tst_textfield.qml15
2 files changed, 23 insertions, 4 deletions
diff --git a/src/quicktemplates2/qquicktextfield.cpp b/src/quicktemplates2/qquicktextfield.cpp
index f0008a59..397e666e 100644
--- a/src/quicktemplates2/qquicktextfield.cpp
+++ b/src/quicktemplates2/qquicktextfield.cpp
@@ -547,7 +547,8 @@ void QQuickTextField::mousePressEvent(QMouseEvent *event)
QQuickTextInput::mousePressEvent(d->pressHandler.delayedMousePressEvent);
d->pressHandler.clearDelayedMouseEvent();
}
- QQuickTextInput::mousePressEvent(event);
+ if (event->buttons() != Qt::RightButton)
+ QQuickTextInput::mousePressEvent(event);
}
}
@@ -560,7 +561,8 @@ void QQuickTextField::mouseMoveEvent(QMouseEvent *event)
QQuickTextInput::mousePressEvent(d->pressHandler.delayedMousePressEvent);
d->pressHandler.clearDelayedMouseEvent();
}
- QQuickTextInput::mouseMoveEvent(event);
+ if (event->buttons() != Qt::RightButton)
+ QQuickTextInput::mouseMoveEvent(event);
}
}
@@ -573,7 +575,8 @@ void QQuickTextField::mouseReleaseEvent(QMouseEvent *event)
QQuickTextInput::mousePressEvent(d->pressHandler.delayedMousePressEvent);
d->pressHandler.clearDelayedMouseEvent();
}
- QQuickTextInput::mouseReleaseEvent(event);
+ if (event->buttons() != Qt::RightButton)
+ QQuickTextInput::mouseReleaseEvent(event);
}
}
@@ -584,7 +587,8 @@ void QQuickTextField::mouseDoubleClickEvent(QMouseEvent *event)
QQuickTextInput::mousePressEvent(d->pressHandler.delayedMousePressEvent);
d->pressHandler.clearDelayedMouseEvent();
}
- QQuickTextInput::mouseDoubleClickEvent(event);
+ if (event->buttons() != Qt::RightButton)
+ QQuickTextInput::mouseDoubleClickEvent(event);
}
void QQuickTextField::timerEvent(QTimerEvent *event)
diff --git a/tests/auto/controls/data/tst_textfield.qml b/tests/auto/controls/data/tst_textfield.qml
index deb4b6ff..dad47e23 100644
--- a/tests/auto/controls/data/tst_textfield.qml
+++ b/tests/auto/controls/data/tst_textfield.qml
@@ -416,4 +416,19 @@ TestCase {
mouseClick(control, rect.x + rect.width / 2, rect.y + rect.height / 2)
compare(control.selectedText, "Qt Quick Controls 2 TextArea")
}
+
+ // QTBUG-64048
+ function test_rightClick() {
+ var control = createTemporaryObject(textField, testCase, {text: "TextField", selectByMouse: true})
+ verify(control)
+
+ control.selectAll()
+ compare(control.selectedText, "TextField")
+
+ mouseClick(control, control.width / 2, control.height / 2, Qt.RightButton)
+ compare(control.selectedText, "TextField")
+
+ mouseClick(control, control.width / 2, control.height / 2, Qt.LeftButton | Qt.RightButton)
+ compare(control.selectedText, "")
+ }
}