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 :
GIFrecord_2015-04-28_160010.gif
And here's the code where I start the drag event :
void ActionButtonWidget
::mouseMoveEvent(QMouseEvent * event
) {
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();
}
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();
}
To copy to clipboard, switch view to plain text mode
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.
Bookmarks