当前位置:网站首页>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。
咨询作者请使用微信公众号搜索:“上官宏竹”,或者扫下面的二维码,后台留言咨询。
边栏推荐
- Apache POI implements excel import, read data, write data and export
- 关于servlet中实现网站的页面跳转
- Apache POI实现Excel导入读取数据和写入数据并导出
- SM integration is as simple as before, and the steps are clear (detailed)
- Lenovo Savior r7000+ add ssd+ copy and partition the information of the original D disk to the new SSD
- [config] configure array parameters
- Vivo market API event reporting and docking
- Arfoundation starts from scratch 8-geospatial API (geospatial) development
- How to monitor micro web services
- Rolabelimg to data format data
猜你喜欢

Modification of annotation based three-tier project and the way of adding package scanning

Mysql的自连接和联合查询

Arfoundation starts from scratch 8-geospatial API (geospatial) development

ODOO开发教程之透视表

NumPy基础

Mysql语句中的函数

scikit-learn——机器学习应用开发的步骤和理解

JS (foreach) return cannot end the function solution

ARFoundation入门教程10-平面检测和放置
Let you understand several common traffic exposure schemes in kubernetes cluster
随机推荐
Functions in MySQL statements
[untitled]
How does word view document modification traces? How word views document modification traces
Do you remember the process analysis and function implementation of post notification?
MySQL regularly calls preset functions to complete data update
Introduction of JDBC preparestatement+ database connection pool
Word如何查看文档修改痕迹?Word查看文档修改痕迹的方法
那个准时上下班,从不愿意加班加点的人,在我前面升职了...
Ros1 dead chicken data is stored in txt and SQLite
Diagram of odoo development tutorial
Pivot table of odoo development tutorial
office2010每次打开都要配置进度怎么解决?
【微信小程序】swiper滑动页面,滑块左右各露出前后的一部分,露出一部分
优炫数据库启动失败,报网络错误
2022年SPSSPRO认证杯数学建模B题第二阶段方案及赛后总结
MySQL sorts the queried result set according to the specified sequence
Big silent event Google browser has no title
ODOO开发教程之透视表
虚拟偶像的歌声原来是这样生成的!
ThreadPoolExecutor simple to use