2017-09-01 130 views
1

有一個TextArea,我已經設置 porperty到false來阻止虛擬鍵盤彈出,但是當用戶點擊TextArea時,光標位置應該移動。爲了達到這個我認爲mousearea將是不錯的選擇。以下是密碼:將TextArea光標移動到MouseArea上點擊QML

TextArea{ 
    id:textArea 
    text:"ABCDEFGHIJKLMNOPQRSTUVWXYZ"  
    width:100 
    height: 200 
    color: "white" 
    cursorVisible: true 
    activeFocusOnPress: false //To Block virtual Keyboard popup 

    background: Rectangle{ 
     color:"transparent" 
     border.color : "white" 
     border.width:2 
     MouseArea{ 
      id:mousearea 
      anchors.fill:parent 
      onClicked: { 

       //*** How to set cursor position??      
      } 
     } 
    } 
} 
+0

嘗試設置[selectByMouse](http://doc.qt.io/qt-5/qml-qtquick-textedit.html#selectByMouse-prop)爲真,並離開了鼠標區域。 – jpnurmi

回答

2

這個怎麼樣?

textArea.cursorPosition = textArea.positionAt(mouseX, mouseY)