Results 1 to 5 of 5

Thread: Drag and Drop item inside QTreeWidget

  1. #1
    Join Date
    Jul 2008
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Question Drag and Drop item inside QTreeWidget

    Dear,

    I'm new with Qt, it's one day that I'm trying to solve this problem...
    I want to be able to drag and drop elements inside my QTreeWidget but I want that the hierarchy is respected... here an example:

    Qt Code:
    1. tree->setAcceptDrops(true);
    2. tree->setDragEnabled(true);
    3. tree->setDragDropMode(QAbstractItemView::InternalMove);
    4.  
    5. QTreeWidgetItem* dad = new QTreeWidgetItem(tree,0);
    6.  
    7. QTreeWidgetItem* child = new QTreeWidgetItem(dad,0);
    To copy to clipboard, switch view to plain text mode 
    I want to be able to drag and drop only "dad" elements (with its childs attahced obviously) at the same level as the other "dad" elements...
    I hope you can understand my problem... if not please let me know and I'll try to explain it better!
    Thank you very much

    Lisa
    Last edited by jpn; 5th July 2008 at 19:13. Reason: missing [code] tags

  2. #2
    Join Date
    Jul 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drag and Drop item inside QTreeWidget

    Maybe you can override the dropEvent ( QDropEvent * event ) from QAbstractItemView in your QTreeView and do something like that

    Qt Code:
    1. void MyTreeView::dropEvent(QDropEvent * event)
    2. {
    3. QModelIndex dropIndex = indexAt(event->pos());
    4. if (!dropIndex.parent().isValid()) { // if i have no parent, let the event do his job
    5. QTreeView::dropEvent(event);
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 162 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drag and Drop item inside QTreeWidget


  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Drag and Drop item inside QTreeWidget

    Quote Originally Posted by caduel View Post
    You mean QTreeWidgetItem::setFlags(), right?
    J-P Nurmi

  5. #5
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 162 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drag and Drop item inside QTreeWidget

    Sure. Just checking if somebody was paying attention!

Similar Threads

  1. QTreeWidget Drag and drop
    By zell99 in forum Newbie
    Replies: 15
    Last Post: 7th August 2010, 14:28
  2. Drag and Drop in a QTreeWidget subclass
    By kishore in forum Qt Programming
    Replies: 2
    Last Post: 14th May 2008, 08:12
  3. Drag an item from QTreeWidget and drop in TableView
    By steg90 in forum Qt Programming
    Replies: 8
    Last Post: 18th May 2007, 12:42
  4. Drag and drop revisited
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 30th June 2006, 17:41
  5. drag and drop with item views
    By castorvert in forum Qt Programming
    Replies: 14
    Last Post: 27th March 2006, 11:12

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.