关于QML中的MouseArea propagateComposedEvents

本文介绍了在QML中遇到MouseArea叠加时点击事件处理的问题,探讨了MouseArea的propagateComposedEvents属性,以及如何通过设置此属性解决点击事件响应错误的难题。通过对代码的修改和实验,最终找到解决方案,使得点击事件能够正确地作用于目标组件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文长期固定连接,转发请点赞评论

QML中MouseArea叠加的情况处理方式:

今天在学习QML的过程中,发现一个问题,因为是新手,正在学习,所以难免会碰到各种各样的问题。有些难免很奇葩。先上个代码:

import QtQuick 2.8
import QtQuick.Window 2.2

Window {
   
    visible: true
    width:root.width
    height: root.height
    title: qsTr("Hello World")//只有加了qsTr才能被国际化的翻译

    Image {
   
        id: root
        source: "images/background.png"
        width: 960
        height: 640
    }



    Image {
   
        id: pinwheel
        source: "images/pinwheel.png"
        anchors.centerIn: parent
        Behavior on rotation {
   
            NumberAnimation{
   
                duration:250
            }
        }

        MouseArea{
   
            anchors.fill: parent
            onClicked: {
   
                 pinwheel.rotation-=360

            }
        }
    }

    Text {
   
        id: textCenter
        text: qsTr("Hello World")
        anchors.centerIn: parent
    }

    MouseArea{
   
        anchors.fill: root
        onClicked:{
   
            pinwheel.rotation+=360
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值