16 class Drag :
public QLabel {
23 QMimeData* pMimeData =
new QMimeData;
24 pMimeData->setText(text());
26 QDrag* pDrag =
new QDrag(
this);
27 pDrag->setMimeData(pMimeData);
28 pDrag->setPixmap(QPixmap(
":/img1.png"));
29 pDrag->exec(Qt::MoveAction);
35 if (pe->button() == Qt::LeftButton) {
36 m_ptDragPos = pe->pos();
38 QWidget::mousePressEvent(pe);
43 if (pe->buttons() & Qt::LeftButton) {
44 int distance = (pe->pos() - m_ptDragPos).manhattanLength();
45 if (distance > QApplication::startDragDistance()) {
49 QWidget::mouseMoveEvent(pe);
53 Drag(QWidget* pwgt = 0) : QLabel(
"This is a draggable text", pwgt)
virtual void mouseMoveEvent(QMouseEvent *pe)
virtual void mousePressEvent(QMouseEvent *pe)