Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

SwipeView swipes when it shouldn't



    1. I have a SwipeView with 3 pages.
    2. One page has a CustomKnob, which is simply an Image with a MouseArea filling it
    3. You click and drag on the Image in the y direction to edit the knob. It works great, I change the knob image as I drag in Y and it looks good
    4. Now, I'd like to have any click and drag in x on the Knob not pass to the SwipeView, because it should not pass through. I tried adding this to the MouseArea:

    onMouseXChanged: {
    mouse.accepted = true
    }

    This does not cause the SwipeView to ignore minor movement in X when swiping on the Knob in y

    What can I do to get SwipeView to ignore X dragging on a child control? Normally these types of events do not propagate through a MouseArea. A parent widget will not act on it and treat it as a swipe gesture.

    Qt 5.15.2

    QML SwipeView



  • Here's some example code. How can it be changed so that clicking and dragging in the x direction on the orange square is ignored by the SwipeView?

    import QtQuick 2.12
    import QtQuick.Controls 2.5

    ApplicationWindow {
    id: appWindow
    width: 640; height: 480
    visible: true

    SwipeView {
        id: swipeView
        anchors.fill: parent
        currentIndex: 1
    
        Rectangle {
            width: appWindow.width; height: appWindow.height
            color: "red"
        }
    
        Rectangle {
            width: appWindow.width; height: appWindow.height
            color: "green"
    
            Rectangle {
                width: 100; height: 100
                anchors.centerIn: parent
                color: "orange"
    
                MouseArea {
                    anchors.fill: parent
    
                    onMouseXChanged: {
                        mouse.accepted = true
                    }
                }
            }
        }
    
        Rectangle {
            width: appWindow.width; height: appWindow.height
            color: "blue"
        }
    
    } // end SwipeView
    

    }



  • Setting MouseArea.preventStealing to true might work.



  • Hi jeremy_k,

    Thanks for the idea.

    I tried adding preventStealing: true to the MouseArea, but it didn't help.

    I'm beginning to think there is no way to tell a SwipeView to not swipe when children controls are being clicked and dragged. That's a serious flaw that no one would want. I wonder if it ever worked properly.

    Thanks again for your thoughts.

    • Steve

Log in to reply