qt Qml qml MouseArea的属性和信号方法

Mousearea

属性:

acceptedButtons:​接受的鼠标按键,默认是左键

Qt.LeftButton | Qt.RightButton | Qt.AllButtons等等

pressedButtons:​按下的是什么键?左键or右键等

Rectangle{
        color: "yellow"
        anchors.centerIn: parent
        width: 200
        height: 200
        MouseArea {
            id: mouseArea
            anchors.fill: parent
            acceptedButtons: Qt.LeftButton | Qt.RightButton
            onPressed: {
            var ret =pressedButtons & Qt.RightButton
            console.log(ret? "right":"left")
            }

        }
    }

hoverEnabled :bool​是否开启触发光标悬浮的层

containsMouse : bool​光标是不是在这我的area里面

containsPress : bool​光标是不是在area里面按下

Rectangle{
        color: "yellow"
        anchors.centerIn: parent
        width: 200
        height: 200
        MouseArea {
            id: mouseArea
            anchors.fill: parent
            hoverEnabled:true
            acceptedButtons: Qt.LeftButton | Qt.RightButton
            onPressed: {
            var ret =pressedButtons & Qt.RightButton
            console.log(ret? "right":"left")
            }
            onContainsMouseChanged: {console.log("onContainsMouseChanged",containsMouse)}
            onContainsPressChanged: {console.log("onContainsPressChanged",containsPress)}

        }
    }

cursorShape : Qt::CursorShape​光标的样式选择,进入area后会变样式

MouseArea {
            id: mouseArea
            anchors.fill: parent
            hoverEnabled:false
            cursorShape: Qt.SplitVCursor
            acceptedButtons: Qt.LeftButton | Qt.RightButton
            onPressed: {
            var ret =pressedButtons & Qt.RightButton
            console.log(ret? "right":"left")
            }
            onContainsMouseChanged: {console.log("onContainsMouseChanged",containsMouse)}
            onContainsPressChanged: {console.log("onContainsPressChanged",containsPress)}

drag​拖动

  • drag.target : Item​指定控件
  • drag.active : bool
  • drag.axis : enumeration​指定轴
  • drag.minimumX : real​指定值
  • drag.maximumX : real​指定值
  • drag.minimumY : real​指定值
  • drag.maximumY : real​指定值
  • drag.filterChildren : bool​指定子控件是否继承拖动
  • drag.threshold : real
  Rectangle {
      id: container
      width: 600; height: 200

      Rectangle {
          id: rect
          width: 50; height: 50
          color: "red"
          opacity: (600.0 - rect.x) / 600

          MouseArea {
                 anchors.fill: parent
                 drag.target: rect
                 drag.axis: Drag.XAxis|Drag.YAxis
                 drag.minimumX: 0
                 drag.maximumX: container.width - rect.width
             }
      }
  }

enabled : bool​是否使能area

mouseX : real​光标在区域移动的坐标 需要hoverEnabled :bool​联动
mouseY : real​光标在区域移动的坐标 需要hoverEnabled :bool​联动

pressAndHoldInterval : int​长按触发信号的时间 单位ms

propagateComposedEvents : bool​子area是否可以触发父area的信号

信号函数:

clicked:​鼠标的点击

pressed:​按下鼠标

relesed:​松开鼠标

  • 20
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值