Results 1 to 7 of 7

Thread: QTreeView & DragNDrop

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2006
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default QTreeView & DragNDrop

    Hi all!

    i want use drag and drop functionalities for the QTreeView using

    Qt::DropActions QAbstractItemModel::supportedDropActions () const
    QStringList QAbstractItemModel::mimeTypes () const
    bool QAbstractItemModel::dropMimeData ( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent )

    Please, anybody lay out some example or email me!

    Thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeView & DragNDrop

    Appropriate examples are available with Qt distribution in examples/itemviews directory.

  3. #3
    Join Date
    Jul 2006
    Location
    Slovakia
    Posts
    17
    Thanks
    12
    Thanked 6 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView & DragNDrop

    Hello,

    see this thread, http://www.qtcentre.org/forum/f-newb...lass-2992.html

    First post has attachement with simple DragNDrop implemented with subclassed QTreeWidget, maybe this will help you.

  4. #4
    Join Date
    Jul 2006
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeView & DragNDrop

    Hi,

    I'm trying to implement the drag and drop with QTreeView using
    models. I'm reimplementing dropMimeData() but sometimes I have problems
    because the row or the column parameter is -1.

    Why such thing occurs?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeView & DragNDrop

    When row or column is -1, it means that you are dropping on a parent. In such a case the parent index will be valid and it is your resposibility to add a new child to the parent and "install" the data carried by the drag in the new item.

  6. #6
    Join Date
    Jul 2006
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeView & DragNDrop

    One more question:

    Qt Code:
    1. Qt::DropActions NowPlayingModel::supportedDropActions() const{
    2.  
    3. return Qt::CopyAction | Qt::MoveAction;
    4.  
    5. }
    To copy to clipboard, switch view to plain text mode 

    I want to move the data from the source to the target, but if i return only Qt::MoveAction, i am unable to drop the item anywhere in the tree view.

    what is the matter?

    Thanks

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeView & DragNDrop

    You have to always support CopyAction... Always... You might not use it yourself, but it has to be mentioned in the supported actions list (probably because it is the default action for all drags, for other types you need some key combos while dragging).

Similar Threads

  1. QTreeView repaint
    By graeme in forum Qt Programming
    Replies: 17
    Last Post: 13th March 2012, 13:27
  2. paint QTreeView item !!
    By mcenatie in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2006, 14:24
  3. QSortFilterProxyModel & QTreeView
    By Bear in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2006, 15:04
  4. Drag & drop for QTreeView
    By yogeshm02 in forum Qt Programming
    Replies: 2
    Last Post: 30th January 2006, 14:32
  5. How to dispay an icon in the first column of QTreeView
    By yogeshm02 in forum Qt Programming
    Replies: 1
    Last Post: 5th January 2006, 15:51

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.