找回密码
 立即注册
收起左侧

Control 2若干问题之Pop

0
回复
5098
查看
[复制链接]
累计签到:3 天
连续签到:1 天
来源: 2016-12-13 10:15:58 显示全部楼层 |阅读模式
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自己写的右键菜单,没有**,没有炮,我们有火药和钢铁。。。。自己造吧!哎,揪心!!!!

源代码:
  1. import QtQuick 2.7
  2. import QtQuick.Controls 2.0

  3. MenuItem {
  4.     id: menuItem
  5.     hoverEnabled: true
  6.     width: parent.width
  7.     height:30

  8.     contentItem:Text {
  9.         text: menuItem.text
  10.         font: menuItem.font
  11.         color: "black"
  12.         horizontalAlignment: Text.AlignLeft
  13.         verticalAlignment: Text.AlignVCenter
  14.         opacity: menuItem.enabled ? 1 : 0.3
  15.         elide: Text.ElideRight
  16.     }

  17.     background: Rectangle {
  18.         readonly property color colorNormal: Qt.rgba(0.9451,0.9451,0.9451,1.0)
  19.         readonly property color colorHover: Qt.rgba(0.7725,0.7725,0.7725,1.0)
  20.         readonly property color colorPress: Qt.rgba(0.6824,0.6824,0.6824,1.0)
  21.         opacity: menuItem.enabled ? 1 : 0.3
  22.         color: menuItem.pressed ? colorPress:(menuItem.hovered ? colorHover: colorNormal)

  23.         Rectangle{
  24.             width: parent.width
  25.             height: 1
  26.             color: parent.colorPress
  27.             anchors.bottom: parent.bottom
  28.             anchors.left: parent.left
  29.         }
  30.     }

  31. }
复制代码

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了