akiross
24th February 2008, 19:02
Hi there :)
First time using drag-n-drop so I'm posting here ;) Btw, qt 4.3.
I'm doing an application with a QListView wich contains some icons, this list acts like a "repository": these icons will be later used (dragged) in the application itself.
Anyway, I'd like to allow users to drag their image files from the desktop to the list view above.
I read the Model Subclassing Reference and the Using Drag and Drop with Item Views chapters (in addition to the Drag and drop one), ending up doing this:
creating a new model, subclassing QStandardItemModel
reimplementing
supportedDropActions()
flags()
mimeTypes()
dropMimeData()
Actually now I'm just trying to do something easy, like messageBoxing somewhere that mime data has been dropped. Later i'll do data processing.
So, just to see how drop works, the functions are these:
Qt::DropActions PieceModel::supportedDropActions() const {
return Qt::CopyAction | Qt::MoveAction;
}
QStringList PieceModel::mimeTypes() const {
QStringList mimes;
mimes << "image/*";
return mimes;
}
Qt::ItemFlags PieceModel::flags(const QModelIndex &index) const {
Qt::ItemFlags defaultFlags = QStandardItemModel::flags(index);
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
}
bool PieceModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex & parent) {
return true;
}
But actually the desktop manager (KDE in my case) won't allow me to drop something on there, even if
PieceModel *piecesModel = new PieceModel(this);
QListView *piecesView = new QListView(0);
piecesView->setModel(piecesModel);
piecesView->setDragEnabled(true);
piecesView->setAcceptDrops(true);
piecesView->setDropIndicatorShown(true);
What am I doing wrong?
Thanks :)
~Aki
First time using drag-n-drop so I'm posting here ;) Btw, qt 4.3.
I'm doing an application with a QListView wich contains some icons, this list acts like a "repository": these icons will be later used (dragged) in the application itself.
Anyway, I'd like to allow users to drag their image files from the desktop to the list view above.
I read the Model Subclassing Reference and the Using Drag and Drop with Item Views chapters (in addition to the Drag and drop one), ending up doing this:
creating a new model, subclassing QStandardItemModel
reimplementing
supportedDropActions()
flags()
mimeTypes()
dropMimeData()
Actually now I'm just trying to do something easy, like messageBoxing somewhere that mime data has been dropped. Later i'll do data processing.
So, just to see how drop works, the functions are these:
Qt::DropActions PieceModel::supportedDropActions() const {
return Qt::CopyAction | Qt::MoveAction;
}
QStringList PieceModel::mimeTypes() const {
QStringList mimes;
mimes << "image/*";
return mimes;
}
Qt::ItemFlags PieceModel::flags(const QModelIndex &index) const {
Qt::ItemFlags defaultFlags = QStandardItemModel::flags(index);
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
}
bool PieceModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex & parent) {
return true;
}
But actually the desktop manager (KDE in my case) won't allow me to drop something on there, even if
PieceModel *piecesModel = new PieceModel(this);
QListView *piecesView = new QListView(0);
piecesView->setModel(piecesModel);
piecesView->setDragEnabled(true);
piecesView->setAcceptDrops(true);
piecesView->setDropIndicatorShown(true);
What am I doing wrong?
Thanks :)
~Aki