{
QLabel *child
= static_cast<QLabel
*>
(childAt
(event
->pos
()));
if (!child)
return;
dataStream << pixmap <<
QPoint(event
->pos
() - child
->pos
());
mimeData->setData("application/x-dnditemdata", itemData);
drag->setMimeData(mimeData);
drag->setPixmap(pixmap);
drag->setHotSpot(event->pos() - child->pos());
if (event->button()==Qt::RightButton){
QImage tempImage
= pixmap.
toImage();
//rotate abt 60 degrees
matrix.rotate(60);
tempImage = tempImage.transformed(matrix);
painter.begin(&tempImage);
painter.fillRect(tempImage.rect(),
painter.end();
child
->setPixmap
(QPixmap::fromImage(tempImage
));
}
else
{
painter.begin(&tempPixmap);
painter.
fillRect(pixmap.
rect(),
QColor(127,
127,
127,
127));
painter.end();
child->setPixmap(tempPixmap);
}
if (drag->start(Qt::CopyAction | Qt::MoveAction) == Qt::MoveAction)
child->close();
else {
child->show();
child->setPixmap(pixmap);
}
}
void DragWidget::mousePressEvent(QMouseEvent *event)
{
QLabel *child = static_cast<QLabel*>(childAt(event->pos()));
if (!child)
return;
QPixmap pixmap = *child->pixmap();
QByteArray itemData;
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
dataStream << pixmap << QPoint(event->pos() - child->pos());
QMimeData *mimeData = new QMimeData;
mimeData->setData("application/x-dnditemdata", itemData);
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->setPixmap(pixmap);
drag->setHotSpot(event->pos() - child->pos());
if (event->button()==Qt::RightButton){
QImage tempImage = pixmap.toImage();
//rotate abt 60 degrees
QMatrix matrix;
matrix.rotate(60);
tempImage = tempImage.transformed(matrix);
QPainter painter;
painter.begin(&tempImage);
painter.fillRect(tempImage.rect(),
QColor(127, 127, 127, 127));
painter.end();
child->setPixmap(QPixmap::fromImage(tempImage));
}
else
{
QPixmap tempPixmap = pixmap;
QPainter painter;
painter.begin(&tempPixmap);
painter.fillRect(pixmap.rect(), QColor(127, 127, 127, 127));
painter.end();
child->setPixmap(tempPixmap);
}
if (drag->start(Qt::CopyAction | Qt::MoveAction) == Qt::MoveAction)
child->close();
else {
child->show();
child->setPixmap(pixmap);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks