onDoubleClicked can not change the page of SwipeView whereas onClicked can
-
SwipeView { id: swipeView anchors.fill: parent currentIndex: 0 Page { ToolButton { text: "Next" onClicked: swipeView.incrementCurrentIndex() // works fine //onDoubleClicked: swipeView.incrementCurrentIndex() <- did not work } } Page { ToolButton { text: "Prev" onClicked: swipeView.decrementCurrentIndex() // works fine //onDoubleClicked: swipeView.decrementCurrentIndex() <- did not work } } }
onDoubleClicked is emitted properly but SwipeView does not change the page, whether someone know what I am doing wrong here?
-
@QLab
You are doing nothing wrong. It is due to the complex timing considerations at play here. One way you can verify that is to setswipeView.interactive
tofalse
. You will see that the double-clicks work then.With that in mind, it is up to you to choose the best solution, the most horrible of which is to use yet another timer to trigger after the double-click (since issuing the
incrementCurrentIndex()
ordecrementCurrentIndex()
immediately within theonDoubleClicked()
handler does not work in theinteractive
case. If you do use a timer, then the interval of that timer may not be too short, or again, it will not work.Solutions can also depend on the device you target. For example, the following approach works on a PC, but not on a touch device, because it relies on the
containsMouseChanged
eventSwipeView { id: swipeView anchors.fill: parent currentIndex: 0 interactive: true Page { id: page1 Label { height: 40 width: 80 text: "Prev" horizontalAlignment : Text.AlignHCenter verticalAlignment : Text.AlignVCenter background: Rectangle {color: "lightgrey"} MouseArea { anchors.fill: parent onContainsMouseChanged: swipeView.interactive = !containsMouse onDoubleClicked: swipeView.incrementCurrentIndex() } } } Page { id: page2 Label { height: 40 width: 80 horizontalAlignment : Text.AlignHCenter verticalAlignment : Text.AlignVCenter background: Rectangle {color: "lightgrey"} text: "Next" MouseArea { anchors.fill: parent onContainsMouseChanged: swipeView.interactive = !containsMouse onDoubleClicked: swipeView.decrementCurrentIndex() } } } }
If you do target a touch device (which is likely, since you use a
SwipeView
), then you will have to find another way. Hopefully, the above will give you some ideas. -
@Diracsbracket Thanks, you are right, when I changed
swipeView.interactive
tofalse
it works fine. I am newbie in qml but for me it looks like a bug, why qml engine can not properly recognize double click events in interactive mode? Is it not a candidate for bug report? -
@QLab
I don't think this is a bug.It is because there are so many timing considerations to take into account here: is the user clicking or flicking? is the user double-clicking? Is the user flicking or dragging? Should the
Button
or theFlickable
have precedence when the area is first touched, etc...
When you think about it (or better, if you try to implement such behaviors yourself), you will realize how complex this actually is.