summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/controls/ComboBox.qml10
-rw-r--r--tests/auto/controls/data/tst_combobox.qml32
2 files changed, 41 insertions, 1 deletions
diff --git a/src/controls/ComboBox.qml b/src/controls/ComboBox.qml
index 74c2a196..838f7808 100644
--- a/src/controls/ComboBox.qml
+++ b/src/controls/ComboBox.qml
@@ -85,6 +85,10 @@ Control {
/*! The text of the currently selected item in the ComboBox. */
readonly property alias currentText: popup.selectedText
+ /*! This property specifies whether the combobox should gain active focus when pressed.
+ The default value is \c false. */
+ property bool activeFocusOnPress: false
+
/*! \internal */
readonly property bool __pressed: mouseArea.pressed && mouseArea.containsMouse || popup.__popupVisible
/*! \internal */
@@ -100,7 +104,11 @@ Control {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
- onPressedChanged: if (pressed) popup.show()
+ onPressed: {
+ if (comboBox.activeFocusOnPress)
+ forceActiveFocus()
+ popup.show()
+ }
}
Component.onCompleted: {
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml
index d6b5f540..5dbf2921 100644
--- a/tests/auto/controls/data/tst_combobox.qml
+++ b/tests/auto/controls/data/tst_combobox.qml
@@ -54,6 +54,15 @@ TestCase {
height:400
property var model
+
+ Timer {
+ id: timer
+ running: true
+ repeat: false
+ interval: 500
+ onTriggered: testCase.keyPress(Qt.Key_Escape)
+ }
+
function init() {
model = Qt.createQmlObject("import QtQuick 2.1; ListModel {}", testCase, '')
model.append({ text: "Banana", color: "Yellow" })
@@ -192,5 +201,28 @@ TestCase {
verify(!control.control3.activeFocus)
control.destroy()
}
+
+ function test_activeFocusOnPress(){
+ if (Qt.platform.os === "mac")
+ skip("When the menu pops up on OS X, it does not return and the test fails after time out")
+
+ var comboBox = Qt.createQmlObject('import QtQuick.Controls 1.0 ; ComboBox { model: 4 }', container, '');
+ comboBox.activeFocusOnPress = false
+ verify(!comboBox.activeFocus)
+ if (Qt.platform.os === "mac") // on mac when the menu open, the __popup function does not return
+ timer.start()
+ else // two mouse clicks to open and close the popup menu
+ mouseClick(comboBox, comboBox.x + 1, comboBox.y + 1)
+ mouseClick(comboBox, comboBox.x + 1, comboBox.y + 1)
+ verify(!comboBox.activeFocus)
+ comboBox.activeFocusOnPress = true
+ if (Qt.platform.os === "mac") // on mac when the menu open, the __popup function does not return
+ timer.start()
+ else // two mouse clicks to open and close the popup menu
+ mouseClick(comboBox, comboBox.x + 1, comboBox.y + 1)
+ mouseClick(comboBox, comboBox.x + 1, comboBox.y + 1)
+ verify(comboBox.activeFocus)
+ comboBox.destroy()
+ }
}
}