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. [Solved] QML and Drag and Drop
Qt 6.11 is out! See what's new in the release blog

[Solved] QML and Drag and Drop

Scheduled Pinned Locked Moved QML and Qt Quick
42 Posts 8 Posters 55.3k 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.
  • K Offline
    K Offline
    kyleplattner
    wrote on last edited by
    #33

    Just a followup question: How can I persist the drag and dropped location so that when the user navigates away from the page and returns the arrangement that the user chose is still present.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Deqing
      wrote on last edited by
      #34

      I guess you need to store the locations in the model.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kyleplattner
        wrote on last edited by
        #35

        I do need to keep the locations of the dragged items. What would be the best way to accomplish this?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Deqing
          wrote on last edited by
          #36

          I'm using C++ data model and store items in a list.

          When drag-and-drop finishes, I will not only move items in the GridView, but also move them inside the list in C++ code at the same time.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sfjam
            wrote on last edited by
            #37

            this can work in one screen,but when i scroll the screen,this does not work,how to change it

            1 Reply Last reply
            0
            • X Offline
              X Offline
              xsacha
              wrote on last edited by
              #38

              Hi sfjam. Can you elaborate on your issue?

              Are you scrolling to a second GridView or scrolling within the GridView?

              My solution for scrolling within a GridView is on the previous page (fourth comment from bottom).

              If you want multiple GridViews, the code gets more complex. Post back if this is what you desire (multi-grid draggable icon layout).

              • Sacha
              1 Reply Last reply
              0
              • F Offline
                F Offline
                fonzi337
                wrote on last edited by
                #39

                Wow, thanks xsacha for putting this together! It's amazing how little code is involved to get such nice complex-looking behavior. :)

                I suggest a small tweak to the code: it looks like if an item at a lower index is in the active state and is moved towards an item of a higher index in the model, the active item is drawn behind the item with the higher model index. Setting the z value of the active item in the state PropertyChanges definition should do the trick:

                @PropertyChanges { target: item; x: loc.mouseX - width/2; y: loc.mouseY - height/2; scale: 0.5; z: 500 }@

                1 Reply Last reply
                0
                • X Offline
                  X Offline
                  xsacha
                  wrote on last edited by
                  #40

                  Thanks, I'll add that :)

                  • Sacha
                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    meolic
                    wrote on last edited by
                    #41

                    If I change line 23 in Main.qml to have "onPressed" instead of "onPressAndHold", the application is not working properly (problem with index). Where is the problem and how to solve it?

                    EDIT: Adding hoverEnabled: true solved this issue. But I'm not sure whether hoverEnabled has important impact on efficiency?

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      meolic
                      wrote on last edited by
                      #42

                      [quote author="Deqing" date="1293608551"]Cool! I solved it by simply moving "parent: loc" into the state "active".
                      [/quote]

                      I am trying the same. But items are not correctly drawn (wrong x,y) if I remove "parent: loc" from Image {id: item ... }.

                      Can you give us your solution, please.

                      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