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:
Code:
Qt::DropActions PieceModel::supportedDropActions() const { return Qt::CopyAction | Qt::MoveAction; } QStringList mimes; mimes << "image/*"; return mimes; } 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
Code:
PieceModel *piecesModel = new PieceModel(this); piecesView->setModel(piecesModel); piecesView->setDragEnabled(true); piecesView->setAcceptDrops(true); piecesView->setDropIndicatorShown(true);
What am I doing wrong?
Thanks :)
~Aki