azsde
28th April 2015, 15:14
Hello,
I'm currently trying to implement a drag'n'drop feature in a small program I'm developing.
The feature is partially working, the item can be dragged from a widget to another, but as the drag begin, the QPixmap associated with it is completely black.
Here's exactly what happens :
11144
And here's the code where I start the drag event :
void ActionButtonWidget::mouseMoveEvent(QMouseEvent * event)
{
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
QByteArray itemData;
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
dataStream << * this;
mimeData->setData("customWidget/actionButton",itemData);
drag->setMimeData(mimeData);
drag->setPixmap(QPixmap(*(this->pixmap()))); //This should be getting the pixmap from my widget right ?
drag->setHotSpot(QPoint(drag->pixmap().width()/2,
drag->pixmap().height()));
Qt::DropAction dropAction = drag->exec();
}
I don't understand why I can't get the result I want, I've even tried to load an external picture into the my QDrag pixmap, but the result is the same, always a black square.
Does anybody have a clue on why it is behaving like this ?
Thank you in advance for your answers !
Regards,
Azsde.
I'm currently trying to implement a drag'n'drop feature in a small program I'm developing.
The feature is partially working, the item can be dragged from a widget to another, but as the drag begin, the QPixmap associated with it is completely black.
Here's exactly what happens :
11144
And here's the code where I start the drag event :
void ActionButtonWidget::mouseMoveEvent(QMouseEvent * event)
{
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
QByteArray itemData;
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
dataStream << * this;
mimeData->setData("customWidget/actionButton",itemData);
drag->setMimeData(mimeData);
drag->setPixmap(QPixmap(*(this->pixmap()))); //This should be getting the pixmap from my widget right ?
drag->setHotSpot(QPoint(drag->pixmap().width()/2,
drag->pixmap().height()));
Qt::DropAction dropAction = drag->exec();
}
I don't understand why I can't get the result I want, I've even tried to load an external picture into the my QDrag pixmap, but the result is the same, always a black square.
Does anybody have a clue on why it is behaving like this ?
Thank you in advance for your answers !
Regards,
Azsde.