QML MouseArea propagate events to buttons

依然范特西╮ 提交于 2019-12-10 17:29:10

问题


I'm a developing an app that has a menu similar to the Gmail/Inbox app menu, for Android. Basically, when you press the button to open the menu, it slides into view. The user can swipe it away or press the buttons on the menu. For the swipe I've used the code SwipeArea from kovrov with a small change to check the speed between press and release - if it's too slow, I don't consider it a swipe. I've also set the propagate property to true on the MouseArea, i.e. propagateComposedEvents: true and added this code for the clicked event:

onClicked: {
    mouse.accepted = false;
}

Now I have the following code:

Button {
    x: 10
    y: 50
    width: 200
    onClicked: {
        console.log("Button clicked!");
    }
}
SwipeArea {
    anchors.fill: parent

    onMove: {
        var newX = menu.x + x;
        if(newX <= menu.maxX && newX >= menu.minX) menu.x = newX;
    }
    onSwipe: {
        if(direction === "left" && timePassed <= menu.fastSwipe) root.hideMenu(menu.x, timePassed);
        else {
            var middle = menu.width/2;
            var end = menu.x + menu.width;
            if(end > middle) root.showMenu(menu.x);
            else if(end <= middle) root.hideMenu(menu.x);
        }
    }
}

If the Button is rendered on top (code below SwipeArea) it works but then the swipe won't work on top of the Button. If the Button is replaced with a MouseArea the event is correctly triggered. It seems the event is not being propagated? Is there a way to propagate the event to the Button? Or do I have to create my own buttons (Rectangle with MouseArea, for example)?

Thank you for your time.

来源:https://stackoverflow.com/questions/30578007/qml-mousearea-propagate-events-to-buttons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!