add focus in qml
[mdictionary] / src / mdictionary / qml / MySpinBox.qml
index 54fe47d..a30ecba 100644 (file)
@@ -30,6 +30,10 @@ Rectangle {
         return value;
     }
 
+    function setFocus(){
+        text_input1.focus=true;
+    }
+
     TextInput {
         id: text_input1
         x: 1
@@ -52,6 +56,15 @@ Rectangle {
             if(focus==false)
                text=stringToInt(text);
         }
+        Keys.onPressed: {
+            if (event.key == Qt.Key_Up)
+                text_input1.text=((stringToInt(text_input1.text)+singleStep)>maxValue)?(maxValue):(stringToInt(text_input1.text)+singleStep);
+            else if (event.key == Qt.Key_Down){
+                text_input1.text=((stringToInt(text_input1.text)-singleStep)<minValue)?(minValue):(stringToInt(text_input1.text)-singleStep);
+                if(isTextInMinValue && stringToInt(text_input1.text)==minValue)
+                    text_input1.text=textInMinValue
+            }
+        }
     }
 
     Timer {
@@ -148,5 +161,11 @@ Rectangle {
             timerDown.running=true;
         }
     }
+    states: [
+        State {
+            name: "focusState"; when: text_input1.focus && rectangle1.enabled;
+            PropertyChanges { target: rectangle1; border.width: 2 }
+        }
+    ]
 }