add focus in qml
[mdictionary] / src / mdictionary / qml / MyTextLineEdit.qml
index 28f697c..004e198 100644 (file)
@@ -13,6 +13,9 @@ Rectangle {
     signal nextCompleter();
     signal prevCompleter();
 
+    signal isFocused();
+    signal checkFocus();
+
     function setText(string) { textInLineEdit = string; }
     function setCompleter(string) { completerItemText.text=string; }
     function hideCompleter() { completerItem.visible=false; }
@@ -27,6 +30,13 @@ Rectangle {
         completerItemText.text="";
     }
 
+    function setFocus(){
+        if(rectangle1.enabled){
+            text_input1.focus=true;
+            isFocused();
+        }
+    }
+
     TextInput {
         id: text_input1
         width: rectangle1.width-20
@@ -43,7 +53,6 @@ Rectangle {
             else
                completerItem.visible=false;
         }
-        focus: rectangle1.focus;
         Keys.priority : Keys.AfterItem
         Keys.onPressed: {
             if ((event.key == Qt.Key_Enter) || (event.key == Qt.Key_Return)){
@@ -70,6 +79,8 @@ Rectangle {
             }
         }
         onTextChanged: rectangle1.textChange(text);
+        onFocusChanged: if(focus) isFocused();
+        onActiveFocusChanged: rectangle1.checkFocus();
     }
 
 
@@ -102,14 +113,14 @@ Rectangle {
 
     states: [
         State {
-            name: "FokusState"; when: text_input1.focus==true && rectangle1.enabled==true;
+            name: "FokusState"; when: text_input1.focus && rectangle1.enabled;
             PropertyChanges {
                 target: rectangle1
                 border.width: 3
             }
         },
         State {
-            name: "DisableState"; when: rectangle1.enabled==false;
+            name: "DisableState"; when: !rectangle1.enabled;
             PropertyChanges { target: shadeDisable; z: 3; opacity: 0.5 }
         }
     ]