2017-08-14 50 views
0

我使用Qt5.7.1 在iOS系統中長按QML的TextInput顯示與選擇本地上下文菜單時停止本地上下文菜單的iOS上的顯示/全選/粘貼物品。如何防止顯示此菜單,同時允許TextInput仍然可編輯。如何使用QML的TextInput

如果我使用Qt 5.6.2,TextInput不顯示這樣的菜單。

使用下面的代碼,我可以阻止在5.7.1中顯示上下文菜單,但是光標位置總是在文本的末尾結束。

import QtQuick 2.5 
import QtQuick.Window 2.0 

Rectangle 
{ 
color: "yellow" 
width: 100; height: 100 


Rectangle { 
    color: "white" 
    width: 100; height: 50 
    anchors.centerIn: parent 


    TextInput{ 
     id:tip 
     text:"test123" 
     anchors.fill: parent 

     onActiveFocusChanged: { 
      console.log("tip onActiveFocusChanged") 
     } 
     onCursorPositionChanged: { 
      console.log("onCursorPositionChanged:" + tip.cursorPosition) 
     } 


     MouseArea { 
      id:ma 
      anchors.fill: parent 
      propagateComposedEvents:true 

      onPressed: { 
       console.log("ma onPressed:" + tip.cursorPosition) 
       mouse.accepted = true 
       tip.focus = false; 

      } 

      onClicked: { 
       console.log("ma onClicked:" + tip.cursorPosition) 
       mouse.accepted = false 
       tip.forceActiveFocus(); 

      } 

      onPressAndHold:{ 
       console.log("ma onPressAndHold") 
       mouse.accepted = true 
       tip.focus = false; 
      } 
     } 
    } 
} 
} 

我不知道是否有更好的方法可以做到這一點,也有一個完全可編輯的TextInput。

回答

0

我可以從下面的黑客顯示在iOS停止編輯菜單:\

import QtQuick 2.5 
import QtQuick.Window 2.0 

Rectangle 
{ 
    color: "yellow" 
    width: 100; height: 100 
    Rectangle { 
     color: "white" 
     width: 100; height: 50 
     anchors.centerIn: parent 

     TextInput{ 
      id:tip 
      text:"test123" 
      anchors.fill: parent 
      MouseArea { 
       id:ma 
       anchors.fill: parent 
       propagateComposedEvents:true 


       onPressed: { 
        mouse.accepted = false 
        tip.focus = false 
        tip.focus = true 
       } 
      } 
      onSelectedTextChanged:tip.deselect() 

     } 
    } 
}