我得到了简单的课程MyStackedWidget
,但看起来它没有触发拖放事件 - 我做错了什么?
#ifndef MYSTACKEDWIDGET_H
#define MYSTACKEDWIDGET_H
#include <QStackedWidget>
class MyStackedWidget : public QStackedWidget
{
Q_OBJECT
public:
MyStackedWidget();
signals:
void dragEnterSignal(QDragEnterEvent *event);
void dropSignal(QDropEvent *event);
void dragMoveSignal(QDragMoveEvent *event);
void dragLeaveSignal(QDragLeaveEvent *event);
public slots:
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dragLeaveEvent(QDragLeaveEvent *event);
};
#endif // MYSTACKEDWIDGET_H
#include "mystackedwidget.h"
#include <QMimeData>
#include <QDragEnterEvent>
MyStackedWidget::MyStackedWidget()
{
setMouseTracking(true);
}
void MyStackedWidget::dragEnterEvent(QDragEnterEvent *event)
{
const QMimeData *mimeData = event->mimeData();
if(mimeData->hasUrls() && mimeData->urls().size() == 1) {
event->acceptProposedAction();
}
emit dragEnterSignal(event);
}
void MyStackedWidget::dropEvent(QDropEvent *event)
{
emit dropSignal(event);
}
void MyStackedWidget::dragMoveEvent(QDragMoveEvent *event)
{
emit dragMoveSignal(event);
}
void MyStackedWidget::dragLeaveEvent(QDragLeaveEvent *event)
{
emit dragLeaveSignal(event);
}