PDA

View Full Version : cursor pixmap during drag&drop



darksaga
18th June 2007, 21:40
Hi there,

I'd like to change the cursor pixmap during my drag & drop event.
Drag & drop works perfectly, its only the pixmap I don't know how to change...

I use a QTableView with a subclassed QSqlRelationalTableModel as my model. To enable dragevents I use the m_tableView->setDragEnabled(true) function.

I know u can set the Pixmap using


QDrag *drag = new QDrag(this);
drag->setPixmap(QPixmap(":/images/drag.png"));

but I don't know, where to use these lines (inside my model, or somewhere else?) or how to do taht exactly?

hope somebody has a solution...

here's the model I'm using:



#ifndef MYQSQLRELATIONALTABLEMODEL_H
#define MYQSQLRELATIONALTABLEMODEL_H

#include <QSqlRelationalTableModel>
#include <QMimeData>
#include <QByteArray>
#include <QDataStream>

class MyQSqlRelationalTableModel : public QSqlRelationalTableModel
{
Q_OBJECT
public:
MyQSqlRelationalTableModel(QObject * parent = 0, QSqlDatabase db = QSqlDatabase()) : QSqlRelationalTableModel(parent, db){}

Qt::DropActions supportedDropActions() const
{
return Qt::CopyAction;
}

Qt::ItemFlags flags(const QModelIndex &index) const
{
Qt::ItemFlags defaultFlags = QAbstractTableModel::flags(index);

if (index.isValid())
return Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
else
return Qt::ItemIsDropEnabled | defaultFlags;
}

QMimeData *mimeData(const QModelIndexList &indexes) const
{
QMimeData *mimeData = new QMimeData();
QByteArray encodedData;
QDataStream stream(&encodedData, QIODevice::WriteOnly);

... //encode my data

mimeData->setData("myMimeData", encodedData);
return mimeData;
}
};
#endif


regards
darksaga

wysota
14th November 2007, 15:55
Unfortunately the model architecture doesn't support that currently (Qt4.3).