Details
-
Sub-task
-
Resolution: Done
-
Not Evaluated
-
None
Description
Run the code below. Click on the blue rectangle to toggle the "enabled" property of the red TextInput element. Note that it turns half-transparent when !enabled. When enabled, click on the red TextInput element to give it activeFocus and note that it turns green. Click on the blue rectangle again and note that the TextInput element turns red (looses activeFocus) when it is !enabled and does not regain activeFocus when enabled until clicked on. Note that when the TextInput element is first given activeFocus its FocusScope also gains activeFocus (becomes yellow) and stays active even then the TextInput looses activeFocus.
Now comment out the first onClicked handler and comment in the second. Repeat the instructions above and note that the TextInput doesn't loose activeFocus when its FocusScope is disabled (it stays green even when disabled, i.e. when half transparent). After disabling and enabling the FocusScope (so that it is green and opaque) click on it and note that it turns red! I.e. it lost activeFocus when forceActiveFocus() was called. Now click on the blue rectangle to disable the TextInput element, and note that the FocusScope looses active focus too, i.e. it turns white (maybe this last bit is expected, but it's different from what happened in initial example).
import QtQuick 1.0 Rectangle { width: 800 height: 480 FocusScope { id: focusScope anchors.fill: parent Rectangle { color: parent.activeFocus ? "yellow" : "white"; anchors.fill: parent } TextInput { id: textInput x: 100; y: 100 width: 300; height: 30 font.pixelSize: 25 text: "Sample text" activeFocusOnPress: false onActiveFocusChanged: print("Active focus: " + activeFocus) opacity: enabled ? 1 : 0.5 Rectangle { color: parent.activeFocus ? "green" : "red" anchors.fill: parent z: -1 } MouseArea { anchors.fill: parent onPressed: parent.forceActiveFocus() } } } MouseArea { width: 100; height: 100 anchors.centerIn: parent onClicked: textInput.enabled = !textInput.enabled //1 works as it should // onClicked: focusScope.enabled = !focusScope.enabled //2 doesn't work Rectangle { color: "blue"; anchors.fill: parent } } }