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 support for TreeView
Forum Updated to NodeBB v4.3 + New Features

Drag and Drop support for TreeView

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 222 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.
  • B Offline
    B Offline
    bidjiz
    wrote on last edited by
    #1

    Hi everyone, I'm trying to implement drag and drop for TreeView. I've ended up with the following QML code for my view:

    TreeView {
    
    	id: tree_view
    
    	model: root.m_model // defined in C++
    
    	selectionModel: ItemSelectionModel {
    		id: selection_model
    	}
    
    	DropArea {
    		id: drop_area
    		anchors.fill: parent
    		
    		onDropped: (drag) => { // <-- never called
    			console.log('DropArea onDropped');
    			var from = drag.sourceDelegate.visualIndex;
    			var to = visualIndex;
    			root.m_model.move(from, to);
    		}
    	}
    
    	delegate: TreeViewDelegate {
    
    		id: tree_delegate
    
    		Drag.source: drag_handler
    		Drag.active: drag_handler.active
    
    		DragHandler {
    			id: drag_handler
    			target: parent
    			cursorShape: Qt.ClosedHandCursor
    			
    			onActiveChanged: {
    
    				console.log('onActiveChanged ', active);
    
    				if (drag_handler.active)
    					drag_handler.parent.Drag.drop()
    			}
    		}
    	}
    }
    

    The problem is that onDropped() is never called. Thus moving tree elements does nothing. I'm missing something obvious here, but what exactly? My Qt version is 6.4.

    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