parent
afab4879e1
commit
08f9384b43
@ -0,0 +1,39 @@ |
||||
#include <QMimeData> |
||||
#include <QDrag> |
||||
#include <QUrl> |
||||
|
||||
#include "UBDraggableLabel.h" |
||||
|
||||
|
||||
UBDraggableLabel::UBDraggableLabel(QWidget *parent) : |
||||
QLabel(parent) |
||||
{ |
||||
} |
||||
|
||||
UBDraggableLabel::~UBDraggableLabel() |
||||
{ |
||||
//NOOP
|
||||
} |
||||
|
||||
void UBDraggableLabel::loadImage(QString imagePath) |
||||
{ |
||||
mSourcePath = imagePath; |
||||
QPixmap pix = QPixmap(mSourcePath); |
||||
setPixmap(pix); |
||||
setScaledContents(true); |
||||
} |
||||
|
||||
void UBDraggableLabel::mousePressEvent(QMouseEvent *event) |
||||
{ |
||||
Q_UNUSED(event); |
||||
QMimeData *mimeData = new QMimeData; |
||||
QList<QUrl> urls; |
||||
urls << QUrl::fromLocalFile(mSourcePath); |
||||
mimeData->setUrls(urls); |
||||
mimeData->setText(mSourcePath); |
||||
|
||||
|
||||
QDrag *drag = new QDrag(this); |
||||
drag->setMimeData(mimeData); |
||||
drag->start(); |
||||
} |
@ -0,0 +1,23 @@ |
||||
#ifndef UBDRAGGABLELABEL_H |
||||
#define UBDRAGGABLELABEL_H |
||||
|
||||
#include <QLabel> |
||||
|
||||
class UBDraggableLabel : public QLabel |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
UBDraggableLabel(QWidget *parent = 0); |
||||
~UBDraggableLabel(); |
||||
void loadImage(QString imagePath); |
||||
signals: |
||||
|
||||
public slots: |
||||
|
||||
protected: |
||||
QString mSourcePath; |
||||
void mousePressEvent(QMouseEvent *event); |
||||
|
||||
}; |
||||
|
||||
#endif // UBDRAGGABLELABEL_H
|
@ -1,5 +1,9 @@ |
||||
|
||||
HEADERS += src/customWidgets/UBWidgetList.h |
||||
HEADERS += src/customWidgets/UBWidgetList.h \ |
||||
src/customWidgets/UBDraggableLabel.h |
||||
|
||||
SOURCES += src/customWidgets/UBWidgetList.cpp \ |
||||
src/customWidgets/UBDraggableLabel.cpp |
||||
|
||||
|
||||
SOURCES += src/customWidgets/UBWidgetList.cpp |
||||
|
||||
|
Loading…
Reference in new issue