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. Drag and Drop in QabstractListModel

Drag and Drop in QabstractListModel

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 876 Views
  • 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.
  • Bhushan_SureB Offline
    Bhushan_SureB Offline
    Bhushan_Sure
    wrote on last edited by
    #1

    Hi,
    I have C++ Model and that model i have given to Qml ListView. I want to implement Drag and Drop in ListView and On Drag-Drop Model items should get swap. I am able to Drag-Drop But as my Model is Define in C++, I am not able to Swap items.

    I know move() method is there for Swap in Model. But for accessing move() method we need "from,to" parameters. I am able to get "from" parameter index. But how will i get "to" parameter index i.e., Drop-Index.

    Thanks,
    Bhushan Sure

    Pradeep P NP 1 Reply Last reply
    0
    • Bhushan_SureB Bhushan_Sure

      Hi,
      I have C++ Model and that model i have given to Qml ListView. I want to implement Drag and Drop in ListView and On Drag-Drop Model items should get swap. I am able to Drag-Drop But as my Model is Define in C++, I am not able to Swap items.

      I know move() method is there for Swap in Model. But for accessing move() method we need "from,to" parameters. I am able to get "from" parameter index. But how will i get "to" parameter index i.e., Drop-Index.

      Thanks,
      Bhushan Sure

      Pradeep P NP Offline
      Pradeep P NP Offline
      Pradeep P N
      wrote on last edited by
      #2

      @Bhushan_Sure

      Please include import QtQml.Models 2.3 or latest supported by your Qt Version.

      You can refer a sample code Using drag and drop with ListView.

      And below is simple example of using DropArea & bit modified.

      delegate: Item {
          id: delegateItem
      
          ---
          ---
      
          DropArea {
              id: dropArea
              anchors { fill: parent; margins: 10 }
      
              onEntered: {
                  listView.model.move(listView.dragItemIndex, delegateItem.DelegateModel.itemsIndex, 1);
                  // Use your C++ model here and implement the move() 
              }
          }
      }
      

      All the best.

      Pradeep Nimbalkar.
      Upvote the answer(s) that helped you to solve the issue...
      Keep code clean.

      Bhushan_SureB 1 Reply Last reply
      6
      • Pradeep P NP Pradeep P N

        @Bhushan_Sure

        Please include import QtQml.Models 2.3 or latest supported by your Qt Version.

        You can refer a sample code Using drag and drop with ListView.

        And below is simple example of using DropArea & bit modified.

        delegate: Item {
            id: delegateItem
        
            ---
            ---
        
            DropArea {
                id: dropArea
                anchors { fill: parent; margins: 10 }
        
                onEntered: {
                    listView.model.move(listView.dragItemIndex, delegateItem.DelegateModel.itemsIndex, 1);
                    // Use your C++ model here and implement the move() 
                }
            }
        }
        

        All the best.

        Bhushan_SureB Offline
        Bhushan_SureB Offline
        Bhushan_Sure
        wrote on last edited by
        #3

        @Pradeep-P-N Thank you very much :)

        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