PDA

View Full Version : QTreeView & DragNDrop



itan
4th August 2006, 12:10
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

wysota
4th August 2006, 18:57
Appropriate examples are available with Qt distribution in examples/itemviews directory.

sector
4th August 2006, 20:32
Hello,

see this thread, http://www.qtcentre.org/forum/f-newbie-4/t-how-to-access-class-member-from-other-class-2992.html

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

itan
8th August 2006, 12:05
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?

wysota
8th August 2006, 14:26
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.

itan
8th August 2006, 15:26
One more question:


Qt::DropActions NowPlayingModel::supportedDropActions() const{

return Qt::CopyAction | Qt::MoveAction;

}

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

wysota
9th August 2006, 23:33
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).