首页 > 其他 > 详细

【转载】 qml: MouseArea重叠问题;

时间:2018-04-24 14:41:53      阅读:293      评论:0      收藏:0      [点我收藏+]

原文: https://blog.csdn.net/qq_15024587/article/details/80000443

MouseArea控件大家应该是很熟悉的了.   使用起来也是非常方便的说.   但是在使用MouseArea的时候也有些需要我们注意的地方.我在开发的过程中就遇到了一些问题,现在就分享一下.

代码片段1:

 

Item {
        width: 860
        height: 640


        Button{
            width: 86
            height: 64
            anchors.centerIn: parent
            onClicked: {
                console.log("button clicked")
            }
        }

        MouseArea{
            anchors.fill: parent
            onClicked: {
                console.log("mouseArea clicked")
            }
        }

    }

 

代码片段2:

 

Item {
        width: 860
        height: 640

        MouseArea{
            anchors.fill: parent
            onClicked: {
                console.log("mouseArea clicked")
            }
        }

        Button{
            width: 86
            height: 64
            anchors.centerIn: parent
            onClicked: {
                console.log("button clicked")
            }
        }



    }

 

大家可以看到这两段代码的不同之处就是MouseArea的为何和Button的位置坐了互换.  但是就是这样一个简单的操作会出现意想不到的情况,带代码片段1的运行情况是无论点击这个Item区域还是Button按钮都会出现 mouseArea clicked日志

代码片段2运行的情况是点击Item区域会出现mouseArea clicked日志,但是点击Button按钮会出现button clicked日志.

【转载】 qml: MouseArea重叠问题;

原文:https://www.cnblogs.com/yinwei-space/p/8929808.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!