SwipeView swipes when it shouldn't
-
- I have a SwipeView with 3 pages.
- One page has a CustomKnob, which is simply an Image with a MouseArea filling it
- 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
- 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.5ApplicationWindow {
id: appWindow
width: 640; height: 480
visible: trueSwipeView { 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
-
Unfortunately this is a common theme.
In some cases, I've had success by creating the item to be dragged as a sibling rather than a child of the event stealer. Perhaps keying off the SwipeView.index property to determine when to show the draggable item is workable.
If adding C++ or Python is an option, another avenue is to filter out mouse and touch events during the drag and move the item directly.
Redesigning the interface is usually a more productive path for me.
-
@VStevenP said in SwipeView swipes when it shouldn't:
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.I tried your example code, with just
preventStealing:true
and it worked just as expected, so it does work! -
I recently have described a similar problem here: https://forum.qt.io/topic/124202/qml-swipeview-two-finger-swipe
In other frameworks you simply decouple a SwipeView kind of container from the component it has (that may also support swipe gestures in the same direction) by adding two finger requirement for the container.
So, if you want to swipe the SwipeView, you take two fingers, if you want to swipe the container items, you take one finger.
Unfortunately, it seems, that can‘t be done easily in QML.
-
Sorry for the confusion. I had downgraded from 5.15.2 to 5.12.10 the night I posted the test code, because I was having a problem using root setContextProperty in 5.15.2 in another app of mine.
You are correct! I just retried it, and it works. There was a mistake in my local copy of the test code. I was using preventStealing: false (!),then had commented that out. That's not the proper value, and I'm not sure why I used the value false.
Thanks for helping me overcome my mistake.