Models? Or views? QTreeView and QListView are views not models... And are you sure you need to subclass them? It is rarely needed...
Models? Or views? QTreeView and QListView are views not models... And are you sure you need to subclass them? It is rarely needed...
I meant I had 2 models associated with my 2 views. I'll try not to subclass my views but to use the original ones. In fact, I thought I had to define custom functions for drag and drop in my views, that's why I subclassed the Qt views.
Well, I thought about it, and in my opinion, even if I don't define custom functions, it's better to subclass the view because when I create my object, I can define the delegate, the colour, the setDropEnabled ...
I found sth strange : when I subclass QAbstractListModel, I have to subclass flags() to have Drag and drop enabled. In QAbstractItemModel, there is only :
Qt Code:
{ if (!index.isValid()) return 0; return Qt::ItemIsSelectable|Qt::ItemIsEnabled; }To copy to clipboard, switch view to plain text mode
You don't have to subclass to do that. You use that view only once, so there is no point is subclassing.Originally Posted by castorvert
There is nothing strange in it. flags() from abstract item model just implements the most common behaviour. If you want to have a more complicated model, you have to reimplement flags() along with other modelling methods.I found sth strange : when I subclass QAbstractListModel, I have to subclass flags() to have Drag and drop enabled.
Thank you, i've finally understood what mimeTypes() is.
I have another question, if you please.
Let's take an example :
-I defined supportedDropActions() in a model as following :
-I defined removeRows too.Qt Code:
Qt::DropActions ModeleDispos::supportedDropActions() const{ return Qt::MoveAction; }To copy to clipboard, switch view to plain text mode
-In "QAbstractItemView", it seems that "startDrag" and "dropEvent" use "supportedDropActions" so I think it's possible to move an item into the same view.
-the mimeTypes and mimeData are of the same Type.
but I couldn't move an item into the model.
It worked when I did :
Qt Code:
Qt::DropActions ModeleDispos::supportedDropActions() const{ return Qt::MoveAction|Qt::CopyAction; }To copy to clipboard, switch view to plain text mode
Do you know what could explain that ?
If you just drag an item, it is considered a copy action. To make a move action one has to hold some meta key -- control, alt or shift (I don't remember which) while performing the operation. I think it's possible to force some action but I don't know if it can be done without subclassing the view. Probably it would be easier to emulate a move within one view as a copy and handle it in dropMimeData().
My solution was the following (I subclassed views) :
and :Qt Code:
{ QModelIndexList liste=selectedIndexes(); drag->setMimeData(mimeData); drag->setHotSpot(event->pos() - rect().topLeft()); Qt::DropAction dropAction = drag->start( Qt::MoveAction); if (dropAction == Qt::MoveAction) { model()->removeRows(liste[0].row(),liste.size(),liste[0].parent()); } }To copy to clipboard, switch view to plain text mode
Qt Code:
{ e->setDropAction(Qt::MoveAction); e->accept(); }To copy to clipboard, switch view to plain text mode
I think it will remind you sth wysota
Thanks for all![]()
tpf80 (21st December 2008)
Well, in fact, my "removeRows" doesn't work because the selected items aren't obligatory following each others.
Hmm... remind me what?Originally Posted by castorvert
![]()
Bookmarks