直接丢代码
import QtQuick 2.0
/*
禁止粘贴文字到输入框
设置banpaste即可
*/
TextInput{
id:inptext
property bool banPaste: false
property bool hasPaste: false
height: 40
width: 100
focus: true
readOnly: hasPaste
Keys.onPressed: {
if(!banPaste)return;
if ((event.key == Qt.Key_V) && (event.modifiers & Qt.ControlModifier )){
hasPaste = true;
}
}
Keys.onReleased: {
if(!banPaste)return;
if(hasPaste){
hasPaste = false;
}
}
}
使用
DDTextInput{
id:inptext
anchors.top: parent.top
height: 40
width: parent.width/2
focus: true
}
DDTextInput{
id:inptext2
anchors.top: parent.top
anchors.left: inptext.right
height: 40
width: parent.width/2
focus: true
banPaste: true
}