QPixmap pixmap("image.png"); QDrag* drag = new QDrag(this); drag->setPixmap(pixmap); drag->exec();
QLabel* label = new QLabel(this); QPixmap pixmap("image.png"); label->setPixmap(pixmap); label->setAlignment(Qt::AlignCenter); label->setFixedSize(pixmap.size()); label->setDragEnabled(true);In this example, a QLabel object is created and its pixmap is set to the created QPixmap object. The label is aligned to the center and its size is fixed to the size of the pixmap. The drag is enabled for the label by calling setDragEnabled() function. The package library for QDrag is Qt libraries.