Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to deal with anchoring while making a QML item Draggable?
Forum Updated to NodeBB v4.3 + New Features

How to deal with anchoring while making a QML item Draggable?

Scheduled Pinned Locked Moved Solved Mobile and Embedded
5 Posts 2 Posters 1.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.
  • R Offline
    R Offline
    Roby Brundle
    wrote on 6 Feb 2018, 18:08 last edited by Roby Brundle 2 Jun 2018, 18:09
    #1

    I have QML which host an image. I need to allow the user to pan the image. Basically be able to drag it around.

    I figured that Drag QML type gives me this capability. It works as well using something like below:

    MyQmlComponent {
        id: myqmlitem
        anchors.top: parent.top
        anchors.horizontalCenter: parent.horizontalCenter
    
        Drag.dragType: Drag.Automatic
    
        MouseArea {
            anchors.fill: parent
            drag.target: myqmlitem
    
            drag {
                axis: Drag.XandYAxis
    
                onActiveChanged: {
                    console.log("Active changed..")
                     
                    anchors.top = undefined
                    anchors.horizontalCenter = undefined
                    // I want to unset the anchors here and reset it back at a later stage. But how?
                }
            }
        }
    }
    

    I figured the anchoring properties are coming in the way of my drag/pan feature. How should I deal with this? Are there any ways to set and unset the anchors? Doing the below doesn't seem to work.

    anchors.top = undefined
    anchors.horizontalCenter = undefined
    

    Basically, I want to unset the anchors when drag is active. And unset it at a later stage. Please suggest if there are other ways to deal with this as well..

    R 1 Reply Last reply 7 Feb 2018, 08:08
    0
    • R Roby Brundle
      6 Feb 2018, 18:08

      I have QML which host an image. I need to allow the user to pan the image. Basically be able to drag it around.

      I figured that Drag QML type gives me this capability. It works as well using something like below:

      MyQmlComponent {
          id: myqmlitem
          anchors.top: parent.top
          anchors.horizontalCenter: parent.horizontalCenter
      
          Drag.dragType: Drag.Automatic
      
          MouseArea {
              anchors.fill: parent
              drag.target: myqmlitem
      
              drag {
                  axis: Drag.XandYAxis
      
                  onActiveChanged: {
                      console.log("Active changed..")
                       
                      anchors.top = undefined
                      anchors.horizontalCenter = undefined
                      // I want to unset the anchors here and reset it back at a later stage. But how?
                  }
              }
          }
      }
      

      I figured the anchoring properties are coming in the way of my drag/pan feature. How should I deal with this? Are there any ways to set and unset the anchors? Doing the below doesn't seem to work.

      anchors.top = undefined
      anchors.horizontalCenter = undefined
      

      Basically, I want to unset the anchors when drag is active. And unset it at a later stage. Please suggest if there are other ways to deal with this as well..

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 7 Feb 2018, 08:08 last edited by
      #2

      @Roby-Brundle
      according to the docs assigning undefined to anchors is the correct way to reset them.

      What is the exact behavior in your case?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      R 1 Reply Last reply 7 Feb 2018, 09:37
      0
      • R raven-worx
        7 Feb 2018, 08:08

        @Roby-Brundle
        according to the docs assigning undefined to anchors is the correct way to reset them.

        What is the exact behavior in your case?

        R Offline
        R Offline
        Roby Brundle
        wrote on 7 Feb 2018, 09:37 last edited by Roby Brundle 2 Jul 2018, 09:45
        #3

        @raven-worx setting it to undefined doesn't help. I have the undefined set already in the code. it doesn't seem to work at all.
        Seems like the anchors i am trying to set and unset do not take affect on myqmlitem ?

        R 1 Reply Last reply 7 Feb 2018, 12:25
        0
        • R Roby Brundle
          7 Feb 2018, 09:37

          @raven-worx setting it to undefined doesn't help. I have the undefined set already in the code. it doesn't seem to work at all.
          Seems like the anchors i am trying to set and unset do not take affect on myqmlitem ?

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 7 Feb 2018, 12:25 last edited by
          #4

          @Roby-Brundle
          and i ask again (one last time):

          What is the exact behavior in your case?

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          R 1 Reply Last reply 7 Feb 2018, 16:58
          0
          • R raven-worx
            7 Feb 2018, 12:25

            @Roby-Brundle
            and i ask again (one last time):

            What is the exact behavior in your case?

            R Offline
            R Offline
            Roby Brundle
            wrote on 7 Feb 2018, 16:58 last edited by
            #5

            @raven-worx The exact behaviour was that the default anchors which are the following

            anchors.top: parent.top
            anchors.horizontalCenter: parent.horizontalCenter
            

            were not getting unset by doing setting it undefined. That means that myqmlcomponent remained anchored to top and horizontalCenter. if they were really getting unset then I would be able to drag myqmlcomponent to different X and Y coordinates.

            But the good news is that I figured this out. I needed to refer to myqmlcomponent when setting it anchors to undefined. Like below:

            onActiveChanged: {
                myqmlcomponent.anchors.top = undefined
                myqmlcomponent.anchors.horizontalCenter = undefined
            }
            

            Now it works fine to unset or reset the anchors well

            1 Reply Last reply
            1

            1/5

            6 Feb 2018, 18:08

            • Login

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