Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. SwipeView swipes when it shouldn't
Qt 6.12 LTS is out! See what's new in the release blog

SwipeView swipes when it shouldn't

Scheduled Pinned Locked Moved Solved QML and Qt Quick
10 Posts 4 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • VStevenPV Offline
    VStevenPV Offline
    VStevenP
    wrote on last edited by VStevenP
    #1
    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

    1 Reply Last reply
    0
    • VStevenPV Offline
      VStevenPV Offline
      VStevenP
      wrote on last edited by
      #2

      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
      

      }

      1 Reply Last reply
      0
      • jeremy_kJ Offline
        jeremy_kJ Offline
        jeremy_k
        wrote on last edited by
        #3

        Setting MouseArea.preventStealing to true might work.

        Asking a question about code? http://eel.is/iso-c++/testcase/

        1 Reply Last reply
        1
        • VStevenPV Offline
          VStevenPV Offline
          VStevenP
          wrote on last edited by
          #4

          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
          J.HilkJ 1 Reply Last reply
          0
          • jeremy_kJ Offline
            jeremy_kJ Offline
            jeremy_k
            wrote on last edited by
            #5

            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.

            Asking a question about code? http://eel.is/iso-c++/testcase/

            1 Reply Last reply
            0
            • VStevenPV VStevenP

              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
              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @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!


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              VStevenPV 1 Reply Last reply
              0
              • W Offline
                W Offline
                waltonjb
                wrote on last edited by waltonjb
                #7

                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.

                1 Reply Last reply
                0
                • J.HilkJ J.Hilk

                  @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!

                  VStevenPV Offline
                  VStevenPV Offline
                  VStevenP
                  wrote on last edited by
                  #8

                  @J-Hilk What version of Qt are you running. I was on 5.15.2 when I encountered this and when that change didn't work for me. Also I am on Mac OS/iOS.

                  J.HilkJ 1 Reply Last reply
                  0
                  • VStevenPV VStevenP

                    @J-Hilk What version of Qt are you running. I was on 5.15.2 when I encountered this and when that change didn't work for me. Also I am on Mac OS/iOS.

                    J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by
                    #9

                    @VStevenP MacOS, Qt5.12

                    but you also imported the 5.12 version of QtQuick in your example🤷‍♂️


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    1 Reply Last reply
                    0
                    • VStevenPV Offline
                      VStevenPV Offline
                      VStevenP
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt
                      • Unsolved