Results 1 to 2 of 2

Thread: How to detect drop is between two items or on one item in QTreeView?

  1. #1
    Join Date
    May 2011
    Posts
    6
    Qt products
    Qt3
    Platforms
    MacOS X

    Default How to detect drop is between two items or on one item in QTreeView?

    Hi,

    i'm using QTreeView connected to a QStandardItemModel (which is based on sqlite database). I want support full drag and drop. So i have to know if a drop is released on one item or between two items. How can i detect this?

    Thanks for any help and hint!

  2. #2
    Join Date
    May 2011
    Posts
    6
    Qt products
    Qt3
    Platforms
    MacOS X

    Default Re: How to detect drop is between two items or on one item in QTreeView?

    I solved it...

    Qt Code:
    1. bool MyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
    2. {
    3. if (parent.isValid())
    4. {
    5. QStandardItem *itemTo = itemFromIndex(parent);
    6. if (row < 0) //dropped on item
    7. qDebug() << "append as child to item: " << itemTo->data().toInt();
    8. else //dropped between two items
    9. {
    10. QModelIndex insert = parent.child(row, column);
    11. itemTo = itemFromIndex(insert);
    12. qDebug() << "insert as sibling before: " << itemTo->data().toInt();
    13. }
    14. }
    15. ....
    16. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 5
    Last Post: 27th March 2013, 00:29
  2. How to detect when item is changed in the table view?
    By schmimona in forum Qt Programming
    Replies: 1
    Last Post: 15th August 2011, 09:06
  3. Replies: 2
    Last Post: 20th August 2010, 05:18
  4. QTreeView different item delegate for child items possible?
    By Royceybaby in forum Qt Programming
    Replies: 4
    Last Post: 7th January 2010, 21:14
  5. Drag & drop items on the same QTreeView
    By wind in forum Qt Programming
    Replies: 2
    Last Post: 11th October 2006, 14:29

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
  •  
Qt is a trademark of The Qt Company.