Results 1 to 5 of 5

Thread: QtreeWidget drag and drop

  1. #1
    Join Date
    May 2009
    Posts
    129

    Default QtreeWidget drag and drop

    Hi all


    Please parden me ,if my question is silly..

    How do implement the drag and drop for inside QTreewidget.. top toplevelitems only accept drops and if it have same item already it has to neglect it.. i tried with

    Qt Code:
    1. void MainWindow::dragEnterEvent(QDragEnterEvent *event)
    2. {
    3. if (event->source() == this) {
    4. event->setDropAction(Qt::MoveAction);
    5. event->accept();
    6. }
    7. void MainWindow::dragEnterEvent(QDragEnterEvent *event)
    8. {
    9. event->accept();
    10.  
    11. void MainWindow::dropEvent(QDropEvent *event)
    12. {
    13. if(ui->treeWidget->topLevelItem(1))
    14. {
    15. // Create a data stream that operates on the binary data
    16. QDataStream ds(&ba, QIODevice::WriteOnly);
    17. // Add each item's text for col 0 to the stream
    18. QMimeData *md = new QMimeData;
    19. // Set the data associated with the mime type foo/bar to ba
    20. md->setData("foo/bar", ba);
    21.  
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    can you any one give a solution to implement the above senario

    Advance Thanks

    Thanks

    Addu

  2. #2
    Join Date
    May 2009
    Posts
    62
    Thanks
    2
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtreeWidget drag and drop

    Use QAbstractItemView::setDragDropMode and QAbstractItemView::setDragEnabled to enable drag & drop on your QTreeWidget.

    Use QStandardItem::setDropEnabled to allow/disallow drops on a specific item.

  3. #3
    Join Date
    May 2009
    Posts
    129

    Default Re: QtreeWidget drag and drop

    Hi All

    I enbled the drag and drop for QTreeWidget ...

    ui->treeWidget->dragDropOverwriteMode();
    ui->treeWidget->setDragEnabled(true);
    ui->treeWidget->setDragDropMode(QAbstractItemView ::InternalMove);

    toplevelitems only accept the drops... I don't know how do implement..and if dropped itmes already is in toplevel childs ,it won't accept...

    Some has replied using QStandardItem..

    I created object for QStandardItem and i assined the the toplevelitem for object.. But it is giving errors.

    Any suggestions are most Welcome..

    Advance Thanks


    Regards

    Addu R

  4. #4
    Join Date
    May 2009
    Posts
    129

    Default Re: QtreeWidget drag and drop

    Hi All


    Still i am struggling with this issue...

    please help me to solve this issue

    Thanks

  5. #5
    Join Date
    May 2009
    Posts
    129

    Default Re: QtreeWidget drag and drop

    Hi All

    How do i set the DropEvent at TreeWidget for Accepting drops Toplevelitems only...

    Please help me

    Thanks in Advance

Similar Threads

  1. QTreeWidget Drag and drop
    By zell99 in forum Newbie
    Replies: 15
    Last Post: 7th August 2010, 14:28
  2. Replies: 1
    Last Post: 18th November 2008, 07:57
  3. QTreeWidget Drag and Drop
    By tommydent in forum Qt Programming
    Replies: 10
    Last Post: 25th August 2008, 16:25
  4. Drag and Drop item inside QTreeWidget
    By nina1983 in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2008, 12:43
  5. Drag and Drop in a QTreeWidget subclass
    By kishore in forum Qt Programming
    Replies: 2
    Last Post: 14th May 2008, 08: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.