Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. onDoubleClicked can not change the page of SwipeView whereas onClicked can
Qt 6.11 is out! See what's new in the release blog

onDoubleClicked can not change the page of SwipeView whereas onClicked can

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 851 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #1
    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?

    DiracsbracketD 1 Reply Last reply
    0
    • ? A Former User
      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?

      DiracsbracketD Offline
      DiracsbracketD Offline
      Diracsbracket
      wrote on last edited by Diracsbracket
      #2

      @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 set swipeView.interactive to false. 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() or decrementCurrentIndex() immediately within the onDoubleClicked() handler does not work in the interactive 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 event

         SwipeView {
              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.

      1 Reply Last reply
      1
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        @Diracsbracket Thanks, you are right, when I changed swipeView.interactive to false 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?

        DiracsbracketD 1 Reply Last reply
        0
        • ? A Former User

          @Diracsbracket Thanks, you are right, when I changed swipeView.interactive to false 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?

          DiracsbracketD Offline
          DiracsbracketD Offline
          Diracsbracket
          wrote on last edited by Diracsbracket
          #4

          @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 the Flickable 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.

          1 Reply Last reply
          0

          • Login

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