import Qt 4.7 Rectangle { id: rectangle1 radius: 10 border.color: "#000666"; property alias textInLineEdit:text_input1.text property bool useCompleter:false signal enterPressed(string text); signal textChange(string text); signal nextCompleter(); signal prevCompleter(); signal isFocused(); signal checkFocus(); function setText(string) { textInLineEdit = string; } function setCompleter(string) { completerItemText.text=string; } function hideCompleter() { completerItem.visible=false; } function addOneChar(){ if(completerItemText.text.length>0) text_input1.text=text_input1.text+completerItemText.text.charAt(0); } function addAllChars(){ text_input1.text=text_input1.text+completerItemText.text; completerItemText.text=""; } function setFocus(){ if(rectangle1.enabled){ text_input1.focus=true; isFocused(); } } TextInput { id: text_input1 width: rectangle1.width-20 height: rectangle1.height*0.6; text: "textInput" transformOrigin: Item.Left anchors.centerIn: parent selectByMouse: true; font.pixelSize: rectangle1.height * .5; onCursorPositionChanged: { moveCursorSelection(cursorPosition); if(cursorPosition==text.length && useCompleter) completerItem.visible=true; else completerItem.visible=false; } Keys.priority : Keys.AfterItem Keys.onPressed: { if ((event.key == Qt.Key_Enter) || (event.key == Qt.Key_Return)){ rectangle1.enterPressed(text_input1.text) completerItem.visible=false; } if(useCompleter){ if (event.key == Qt.Key_Up) rectangle1.nextCompleter(); if (event.key == Qt.Key_Down) rectangle1.prevCompleter(); if ((event.key == Qt.Key_Right) && (cursorPosition==text.length)) addOneChar(); if(Qt.ControlModifier){ if (event.key == Qt.Key_Space){ if(completerItem.visible=false) completerItem.visible=true else addAllChars() } } if(event.key == Qt.Key_Escape) completerItem.visible=false; } } onTextChanged: rectangle1.textChange(text); onFocusChanged: if(focus) isFocused(); onActiveFocusChanged: rectangle1.checkFocus(); } Rectangle { id: completerItem x: text_input1.x + text_input1.positionToRectangle(text_input1.cursorPosition).x +1 y: text_input1.y width: completerItemText.paintedWidth; visible: false; height: text_input1.height color: (completerItemText.text.length>0)?"#5e71fb":"#FFFFFF" opacity: 0.5 Text { id: completerItemText anchors.fill: parent text:"" font.pixelSize: text_input1.font.pixelSize; } } Rectangle { id: shadeDisable anchors.centerIn: parent; radius: parent.radius color: "grey"; opacity: 0 width: parent.width; height: parent.height; } states: [ State { name: "FokusState"; when: text_input1.focus && rectangle1.enabled; PropertyChanges { target: rectangle1 border.width: 3 } }, State { name: "DisableState"; when: !rectangle1.enabled; PropertyChanges { target: shadeDisable; z: 3; opacity: 0.5 } } ] }