thomaspu
6th September 2007, 19:26
I was trying to make a simple example to have a QListView accept a dropped file from the OS and can't seem to get the thing to work. I was reading about it in the Qt Assistant article "Using Drag and Drop with Item Views" and I understand that the view and the model need to be able to accept drops. I'm pretty sure that the view properties are set correctly, but I'm not sure about the model. What am I missing?
Here's the complete code:
#include <QtGui>
class AdvQDirModel: public QDirModel
{
public:
AdvQDirModel(): QDirModel(){ }
~AdvQDirModel() { }
Qt::DropActions supportedDropActions() const
{ return Qt::CopyAction | Qt::MoveAction; }
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
AdvQDirModel model;
QListView listView;
listView.setAcceptDrops(true);
listView.setDropIndicatorShown(true);
listView.setModel(&model);
listView.setWindowTitle(QObject::tr("Dir View"));
listView.resize(320, 240);
listView.show();
return app.exec();
}
Thanks,
Paul
Here's the complete code:
#include <QtGui>
class AdvQDirModel: public QDirModel
{
public:
AdvQDirModel(): QDirModel(){ }
~AdvQDirModel() { }
Qt::DropActions supportedDropActions() const
{ return Qt::CopyAction | Qt::MoveAction; }
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
AdvQDirModel model;
QListView listView;
listView.setAcceptDrops(true);
listView.setDropIndicatorShown(true);
listView.setModel(&model);
listView.setWindowTitle(QObject::tr("Dir View"));
listView.resize(320, 240);
listView.show();
return app.exec();
}
Thanks,
Paul