I am trying to drag an icon from the desktop onto my application, which is nothing more than an empty QGraphicsView window. I receive a QDragEnterEvent, but when I release the mouse button, I do not receive a QDropEvent. What am I doing wrong? Here's my simplified code. Thanks for your help!
#include <QtGui/QApplication>
#include <QMainWindow>
#include <QGraphicsView>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QGraphicsSceneDragDropEvent>
{
//Q_OBJECT // Do I need Q_OBJECT?
public:
protected:
//void dropEvent(QGraphicsSceneDragDropEvent *event);
};
{
setAcceptDrops(true);
}
{
//event->setDropAction(Qt::IgnoreAction);
event->accept();
}
//void MyGraphicsView::dropEvent(QGraphicsSceneDragDropEvent *event)
//{
// event->accept();
// qDebug("here");
//}
{
qDebug("here"); // I NEVER GET TO HERE
event->accept();
}
int main(int argc, char *argv[])
{
MyGraphicsView *view = new MyGraphicsView(scene);
view->setAcceptDrops(true);
window.setCentralWidget(view);
window.resize(640, 480);
window.setAcceptDrops(true);
window.show();
return app.exec();
}
#include <QtGui/QApplication>
#include <QMainWindow>
#include <QGraphicsView>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QGraphicsSceneDragDropEvent>
class MyGraphicsView : public QGraphicsView
{
//Q_OBJECT // Do I need Q_OBJECT?
public:
MyGraphicsView(QGraphicsScene *parent=0);
protected:
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
//void dropEvent(QGraphicsSceneDragDropEvent *event);
};
MyGraphicsView::MyGraphicsView(QGraphicsScene *parent)
: QGraphicsView(parent)
{
setAcceptDrops(true);
}
void MyGraphicsView::dragEnterEvent(QDragEnterEvent *event)
{
//event->setDropAction(Qt::IgnoreAction);
event->accept();
}
//void MyGraphicsView::dropEvent(QGraphicsSceneDragDropEvent *event)
//{
// event->accept();
// qDebug("here");
//}
void MyGraphicsView::dropEvent(QDropEvent *event)
{
qDebug("here"); // I NEVER GET TO HERE
event->accept();
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMainWindow window;
QGraphicsScene *scene = new QGraphicsScene;
MyGraphicsView *view = new MyGraphicsView(scene);
view->setAcceptDrops(true);
window.setCentralWidget(view);
window.resize(640, 480);
window.setAcceptDrops(true);
window.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks