当前位置:网站首页>Qml类型:MouseArea
Qml类型:MouseArea
2022-07-29 05:07:00 【上官宏竹】
Qml类型:MouseArea
MouseArea鼠标点击事件的透传
实现MouseArea
的透传,让鼠标事件从父控件传递到子控件。
建立两个Rectangle
,rect1
和rect2
,rect1
是rect2
的父控件,并且子控件的区域和父控件的区域一样,如下代码(显示为橙色的一个矩形区域,红色的父控件被橙色的子控件所覆盖)。如果在父控件中实现一个覆盖整个父控件的MouseArea
的点击事件,那么默认的情况下,只有父控件接收到点击事件,而子控件不会接收到点击事件。
需要让子控件能接收到父控件的点击消息时,父控件的MouseArea
需要做两个处理:
- 1、设置
propagateComposedEvents
为true
,此属性表示组合的鼠标事件是否会自动传播到与此MouseArea
重叠但视觉堆叠顺序较低的其他MouseArea
。默认情况下,此属性为false。 - 2、在
MouseArea
的消息处理中设置MouseEvent::accepted
为false
,表示让当前的事件继续往下传递。
Rectangle {
id: rect1
width: 328
height: 32
color: "red"
Rectangle {
id: rect2
anchors.fill: parent
color: "orange"
MouseArea {
anchors.fill: parent
onClicked: {
console.log("rect2 clicked 22")
}
}
}
MouseArea {
anchors.fill: parent
propagateComposedEvents : true // 1.
onClicked: {
console.log("rect1 clicked 333")
mouse.accepted = false // 2.
}
}
}
上述代码mouse.accepted = false
中的mouse
是哪来的?
这个mouse
是onClicked
槽函数对应的clicked
信号携带的参数,clicked
信号的声明是:clicked(MouseEvent mouse)
。
如果想让MouseArea不接受鼠标事件可以设置acceptedButtons
为Qt.NoButton
。
咨询作者请使用微信公众号搜索:“上官宏竹”,或者扫下面的二维码,后台留言咨询。
边栏推荐
- tmux随笔
- Raspberry pie 4B + Intel neural computing stick (stick2) +yolov5 feasibility study report
- The method and detailed code of automatically pop-up and QQ group when players visit the website
- How does WPS use smart fill to quickly fill data? WPS method of quickly filling data
- Functions in MySQL statements
- 开区网站打开自动播放音乐的添加跟修改教程
- 带你搞懂 Kubernetes 集群中几种常见的流量暴露方案
- How to monitor micro web services
- 【2022新生学习】第三周要点
- What if the office prompts that the system configuration cannot run?
猜你喜欢
随机推荐
Original code, inverse code, complement code
What if excel is stuck and not saved? The solution of Excel not saved but stuck
JS daily question (10)
Mapper agent development
Arfoundation starts from zero 9-ar anchor
Young freshmen yearn for more open source | here comes the escape guide from open source to employment!
Spark的算子操作列表
MySQL sorts the queried result set according to the specified sequence
向往的开源之多YOUNG新生 | 从开源到就业的避坑指南来啦!
使用Jstack、Jconsole和jvisualvm进行死锁分析
The method and detailed code of automatically pop-up and QQ group when players visit the website
Getting started with solidity
Arfoundation starts from scratch 8-geospatial API (geospatial) development
Scikit learn -- steps and understanding of machine learning application development
网安学习-内网安全1
AttributeError: ‘module‘ object has no attribute ‘create_ connection‘
MySQL regularly calls preset functions to complete data update
电脑无法打开excel表格怎么办?excel打不开的解决方法
7.1-default-arguments
scikit-learn——机器学习应用开发的步骤和理解