Results 1 to 1 of 1

Thread: (PyQt) moving items within a QTreeWidget

  1. #1
    Join Date
    Oct 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Question (PyQt) moving items within a QTreeWidget

    Hi,
    I've been trying to drap and drop one or more QTreeWidgetItem with PyQt but i can't get it to work properly.

    After my QTreeViewWidget is populated i can drap and drop items within the tree with no problems.
    But as soon as i add the "dropEvent" function to my code (to get the source item(s) info and the destination item info and run some post actions) the tree doesn't behave the way it did (which was perfect) before i added this function.

    What happens "onDrop" is, the item i'm dragging simply disappear from the tree (deleted?) but doesn't "get moved" to its destination node (item i'm dropping the source item on)

    You'll find a screenshot of my treeViewWidget so hopefully it will make more sense

    Notes :
    I'm NOT setting up the QTreeView to a "QDirModel" i am just using a folder icon for some of my items. Again this tree is not a physical directory on a drive i'm pulling the info from a database and rebuilding it as a treeview)

    All the informations i'm trying to get out of my dropEvent is my source QTreeWidgetItem(s) and my destination QTreeWidgetItem. That's all.

    I've been reading so many pages about drag and drop for the past few days, but i can't figure it out. I started to learn PyQt recently and i usually find the answers i need on internet but this one is killing me.

    Thanks in advance for your help !

    This treeViewWidget behaves like i want it to behave :
    Qt Code:
    1. def __init__(self, parent=None):
    2. super(treeViewWidget, self).__init__(parent)
    3. self.setAcceptDrops(True)
    4. self.setDragEnabled(True)
    5. self.setDragDropMode(QAbstractItemView.InternalMove)
    6. self.setSelectionMode(QAbstractItemView.ExtendedSelection)
    To copy to clipboard, switch view to plain text mode 

    This one doesn't :

    Qt Code:
    1. class treeViewWidget(QTreeWidget):
    2. def __init__(self, parent=None):
    3. super(treeViewWidget, self).__init__(parent)
    4. self.setAcceptDrops(True)
    5. self.setDragEnabled(True)
    6. self.setDragDropMode(QAbstractItemView.InternalMove)
    7. self.setSelectionMode(QAbstractItemView.ExtendedSelection)
    8.  
    9. def dropEvent(self, event):
    10. print 'drop'
    11. event.accept()
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

Similar Threads

  1. amount of items in QTreeWidget
    By supergillis in forum Qt Programming
    Replies: 4
    Last Post: 1st August 2008, 22:38
  2. QTreeWidget - locating items in viewport
    By kemp in forum Qt Programming
    Replies: 3
    Last Post: 14th December 2007, 15:18
  3. Moving items within a model
    By iswm in forum Qt Programming
    Replies: 1
    Last Post: 11th April 2007, 08:29
  4. Removing items properly from qtreewidget item
    By Djony in forum Qt Programming
    Replies: 6
    Last Post: 21st November 2006, 12:20
  5. moving Qlistview items
    By :db:sStrong in forum Qt Programming
    Replies: 0
    Last Post: 21st February 2006, 12:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.