TextField {
id: textField
placeholderText : qsTr("TextField")
selectByMouse: true
MouseArea {
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.RightButton
onClicked: {
selectStart = textField.selectionStart;
selectEnd = textField.selectionEnd;
curPos = textField.cursorPosition;
contextMenu.x = mouse.x;
contextMenu.y = mouse.y;
contextMenu.popup();
textField.cursorPosition = curPos;
textField.select(selectStart,selectEnd);
}
Menu {
id: contextMenu
MenuItem {
text: qsTr("Cu&t")
onTriggered: {
textField.cut()
}
}
MenuItem {
text: qsTr("&Copy")
onTriggered: {
textField.copy()
}
}
MenuItem {
text: qsTr("&Paste")
onTriggered: {
textField.paste()
}
}
}
}
}
qml TextField的简单使用
最新推荐文章于 2024-03-21 20:25:32 发布