Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Differenciate between item being dropped 'onto' and 'above/underneath' another item
Forum Updated to NodeBB v4.3 + New Features

Differenciate between item being dropped 'onto' and 'above/underneath' another item

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 535 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.
  • WoGiW Offline
    WoGiW Offline
    WoGi
    wrote on last edited by
    #1

    Hi I'm trying to do a custom implementation of the drag and drop methods of the QTreeView.

    It's all working pretty good so far, except for the fact that I'm not sure how to differentiate between an item being dropped onto another item, and an item being dropped underneath/above an other item.

    For sake of demonstration, a super stripped down verison of my current code:

    
    
    from PySide import QtGui, QtCore
    
    class QTreeViewCustom(QtGui.QTreeView):
        def __init__(self):
    
            super(QTreeViewCustom,self).__init__()
    
            self.setDragDropMode(QtGui.QAbstractItemView.InternalMove)
            self.setDragEnabled(True)
            self.setDropIndicatorShown(True)
    
            self.dataModel = QtGui.QStandardItemModel()
            
            self.root = self.dataModel.invisibleRootItem()
            self.root.setDropEnabled(True)
    
            self.setModel(self.dataModel)
            self.setSelectionMode(QtGui.QAbstractItemView.SelectionMode.ContiguousSelection)
    
            #fill the tree with items
            for i in range(10):
                self.root.appendRow(testItem(str(i)))
    
        def dragEnterEvent(self,event):
            index =  self.indexAt(event.pos())
            item = self.dataModel.itemFromIndex(index)
            self.draggedFrom = item.path
            event.acceptProposedAction()
    
        def dropEvent(self,event):
            index =  self.indexAt(event.pos())
            item = self.dataModel.itemFromIndex(index)
            self.draggedTo = item.path
    
            print 'source: ', self.draggedFrom
    
            '''
            would like be to able to do something like this here:
            if DROPPED_ON_TOP:
                print 'target (dropped on top): ', self.draggedTo
            else:
                print 'target: ', self.draggedTo
            ''''
    class testItem(QtGui.QStandardItem):
        def __init__(self,name):
    
            super(testItem,self).__init__()
            self.path = 'test_%s'%name
            self.setText(name)
    

    Thanks!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Maybe you can calcualte it with
      http://doc.qt.io/qt-5/qabstractitemview.html#visualRect
      http://doc.qt.io/qt-5/qabstractitemview.html#indexAt

      You get the drop point from the event
      Then take the rect of the item dropped on
      and see if u think it was top or bottom of it.

      1 Reply Last reply
      1

      • Login

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