Menu {
id: contextMenu
width: 100
height: 30
x: parent.width /3
y: parent.y
MenuItem {
text: "复制"
onTriggered: {
console.log("111111")
}
contentItem: Text {
text: parent.text
color: "white" // 设置字体颜色为蓝色
elide: Text.ElideRight
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
background: Rectangle {
anchors.fill: parent
implicitWidth: 100
implicitHeight: 30
border.color: "silver"
color: "#f1333333" // 设置背景色为浅灰色
}
}
}
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.RightButton // 只接受右键
onPressed: {
if (mouse.button === Qt.RightButton) {
contextMenu.open()
}
}
}
qml Menu菜单自定义背景、字体等属性
于 2024-10-10 17:47:01 首次发布