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
drag
->setPixmap
(QPixmap(":/images/drag.png"));
QDrag *drag = new QDrag(this);
drag->setPixmap(QPixmap(":/images/drag.png"));
To copy to clipboard, switch view to plain text mode
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>
{
Q_OBJECT
public:
Qt::DropActions supportedDropActions() const
{
return Qt::CopyAction;
}
{
if (index.isValid())
return Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
else
return Qt::ItemIsDropEnabled | defaultFlags;
}
QMimeData *mimeData
(const QModelIndexList
&indexes
) const {
... //encode my data
mimeData->setData("myMimeData", encodedData);
return mimeData;
}
};
#endif
#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
To copy to clipboard, switch view to plain text mode
regards
darksaga
Bookmarks