|
1Qter豆
本帖最后由 adadadda 于 2016-12-13 17:02 编辑
问题描述:
想用MenuItem加Menu做一个可以交互的右键菜单,然后悲剧了。。。。具体表现为:当MenuItem在Menu中被点击后,MenuItem无法接收到释放按钮的信号,导致下一次唤出右键菜单时其pressed参数依然为true。我尝试自己构建属性,在press事件和Menu的opened信号事件中重写实现,但是这时候hovered属性也为True,这个我就没有任何办法了。
至于为何我在标题里面说是Pop的漏洞呢,因为Menu继承自Pop,我用Pop加Button,效果也是这样。
我的挣扎:我用Item加Button自己写的右键菜单,没有**,没有炮,我们有火药和钢铁。。。。自己造吧!哎,揪心!!!!
源代码:- import QtQuick 2.7
- import QtQuick.Controls 2.0
- MenuItem {
- id: menuItem
- hoverEnabled: true
- width: parent.width
- height:30
- contentItem:Text {
- text: menuItem.text
- font: menuItem.font
- color: "black"
- horizontalAlignment: Text.AlignLeft
- verticalAlignment: Text.AlignVCenter
- opacity: menuItem.enabled ? 1 : 0.3
- elide: Text.ElideRight
- }
- background: Rectangle {
- readonly property color colorNormal: Qt.rgba(0.9451,0.9451,0.9451,1.0)
- readonly property color colorHover: Qt.rgba(0.7725,0.7725,0.7725,1.0)
- readonly property color colorPress: Qt.rgba(0.6824,0.6824,0.6824,1.0)
- opacity: menuItem.enabled ? 1 : 0.3
- color: menuItem.pressed ? colorPress:(menuItem.hovered ? colorHover: colorNormal)
- Rectangle{
- width: parent.width
- height: 1
- color: parent.colorPress
- anchors.bottom: parent.bottom
- anchors.left: parent.left
- }
- }
- }
复制代码 |
|