当前位置:网站首页>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
- P1009 [noip1998 popularization group] sum of factorials
- Excel怎么筛选出自己想要的内容?excel表格筛选内容教程
- P5714 [deep foundation 3. Case 7] obesity
- Getting started with solidity
- JS (in ES6) sync & await understanding
- 优炫数据库启动失败,报网络错误
- Unity Metaverse(三)、Protobuf & Socket 实现多人在线
- 【config】配置数组参数
- NumPy基础
猜你喜欢

Word如何查看文档修改痕迹?Word查看文档修改痕迹的方法

时间序列分析的表示学习时代来了?

Arfoundation starts from zero 9-ar anchor

< El table column> place multiple pictures

Introduction of JDBC preparestatement+ database connection pool
Let you understand several common traffic exposure schemes in kubernetes cluster

ARFoundation从零开始5-AR图像跟踪

Scikit learn -- steps and understanding of machine learning application development

How to monitor micro web services

Mysql语句中的函数
随机推荐
How does word view document modification traces? How word views document modification traces
7.2-function-overloading
Unity metaverse (III), protobuf & socket realize multi person online
What if excel is stuck and not saved? The solution of Excel not saved but stuck
Functions in MySQL statements
优炫数据库启动失败,报网络错误
How to install Office2010 installation package? How to install Office2010 installation package on computer
Arfoundation starts from scratch 8-geospatial API (geospatial) development
WPS insert hyperlink cannot be opened. What should I do if I prompt "unable to open the specified file"!
Architecture analysis of three-tier project and parameter name injection of construction method
JS daily question (12)
Pivot table of odoo development tutorial
关于servlet中实现网站的页面跳转
[sudden] solve remote: support for password authentication was removed on August 13, 2021. please use a perso
Sparksql inserts or updates in batches and saves data to MySQL
Office提示系统配置无法运行怎么办?
[untitled]
传奇开区网站如何添加流量统计代码
ARFoundation从零开始3-创建ARFoundation项目
ThreadPoolExecutor simple to use