Drag&Drop with QStandardItemModel
Hi,
I have a QListView, which is linked to a QStandardItemModel. I'd like to be able to drop files on that QListView. The problem is, the supportedDropActions method is not supported by this object. This is quite strange, since it inherits QAbstractItemModel which provides this function. Is there a way to do drag & drop with QStandardItemModel ?
Thanks in advance
Re: Drag&Drop with QStandardItemModel
Subclass QStandardItemModel and reimplement the desired method. BTW. "supportedDropActions" returns Qt::CopyAction by default. So you should be able to drop data on it. Maybe you didn't enable dropping in the view?
Re: Drag&Drop with QStandardItemModel
Hi. Thanks for your answer.
Actually, that's more the supportedDropActions which is intersting me, if I subclass QStandardItemModel, what should be the constructor ? Is this correct ? (I'm usually a C coder) :
Code:
#include <QtGui>
Q_OBJECT
public:
PeerListModel
(QWidget *parent
= 0);
};
PeerListModel
::PeerListModel (QWidget *parent
= 0) {}
Re: Drag&Drop with QStandardItemModel
Quote:
Originally Posted by madcat
Is this correct ?
Not quite, it should be:
Code:
#include <QStandardItemModel>
{
Q_OBJECT
public:
PeerListModel
( QObject *parent
= 0 );
};
{
}
Remember that if the constructor's implementation is in a header file, you should add "inline" keyword in front of it.
Re: Drag&Drop with QStandardItemModel
Hi,
actually it is not in the header file, I just pasted both files merged.
Anyway, your solution works just great
Once again, thank you a lot for your help :)