You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- #ifndef MYLISTWIDGET_H
- #define MYLISTWIDGET_H
- #include <QDrag>
- #include <QListWidget>
- #include <QMimeData>
-
- class MyListWidget : public QListWidget {
- public:
- using QListWidget::QListWidget;
-
- protected:
- void startDrag(Qt::DropActions supportedActions) override
- {
- QListWidgetItem *item = currentItem();
- if (!item) return;
-
- QDrag *drag = new QDrag(this);
- QMimeData *mimeData = new QMimeData;
-
- QString type = item->data(Qt::UserRole).toString();
- mimeData->setData("application/x-component", type.toUtf8());
- drag->setMimeData(mimeData);
-
- drag->setPixmap(item->icon().pixmap(iconSize()));
- drag->setHotSpot(drag->pixmap().rect().center());
-
- drag->exec(Qt::CopyAction);
- }
- };
-
- #endif // MYLISTWIDGET_H
|