d_stranz
31st July 2020, 00:49
I cannot get drag and drop to work under Qt 5.11.1 x64 on Windows 10, VS 2015. Here's an absolute minimum example. The dummy variables in the event handlers are just to allow me to set breakpoints. None of the drag or drop event handlers is ever hit, when for example, dragging a file from Windows Explorer onto the app.
Anyone know of a problem with this?
Edit: Same behavior if I replace QMainWindow with QDialog or QWidget as the base class.
// dragdroptest.h
#ifndef DRAGDROPTEST_H
#define DRAGDROPTEST_H
#include <QtWidgets/QMainWindow>
class DragDropTest : public QMainWindow
{
Q_OBJECT
public:
DragDropTest(QWidget *parent = 0);
~DragDropTest();
protected:
void dragEnterEvent( QDragEnterEvent * pEvent );
void dragMoveEvent( QDragMoveEvent * pEvent );
void dragLeaveEvent( QDragLeaveEvent * pEvent );
void dropEvent( QDropEvent * pEvent );
private:
};
#endif // DRAGDROPTEST_H
// dragdroptest.cpp
#include "dragdroptest.h"
DragDropTest::DragDropTest(QWidget *parent)
: QMainWindow(parent)
{
setAcceptDrops( true );
// Doesn't matter whether a central widget is set or not.
// setCentralWidget( new QWidget( this ) );
}
DragDropTest::~DragDropTest()
{
}
void DragDropTest::dragEnterEvent( QDragEnterEvent * pEvent )
{
int foo = 42;
}
void DragDropTest::dragMoveEvent( QDragMoveEvent * pEvent )
{
int foo = 42;
}
void DragDropTest::dragLeaveEvent( QDragLeaveEvent * pEvent )
{
int foo = 42;
}
void DragDropTest::dropEvent( QDropEvent * pEvent )
{
int foo = 42;
}
// main.cpp
#include "dragdroptest.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
DragDropTest w;
w.show();
return a.exec();
}
Anyone know of a problem with this?
Edit: Same behavior if I replace QMainWindow with QDialog or QWidget as the base class.
// dragdroptest.h
#ifndef DRAGDROPTEST_H
#define DRAGDROPTEST_H
#include <QtWidgets/QMainWindow>
class DragDropTest : public QMainWindow
{
Q_OBJECT
public:
DragDropTest(QWidget *parent = 0);
~DragDropTest();
protected:
void dragEnterEvent( QDragEnterEvent * pEvent );
void dragMoveEvent( QDragMoveEvent * pEvent );
void dragLeaveEvent( QDragLeaveEvent * pEvent );
void dropEvent( QDropEvent * pEvent );
private:
};
#endif // DRAGDROPTEST_H
// dragdroptest.cpp
#include "dragdroptest.h"
DragDropTest::DragDropTest(QWidget *parent)
: QMainWindow(parent)
{
setAcceptDrops( true );
// Doesn't matter whether a central widget is set or not.
// setCentralWidget( new QWidget( this ) );
}
DragDropTest::~DragDropTest()
{
}
void DragDropTest::dragEnterEvent( QDragEnterEvent * pEvent )
{
int foo = 42;
}
void DragDropTest::dragMoveEvent( QDragMoveEvent * pEvent )
{
int foo = 42;
}
void DragDropTest::dragLeaveEvent( QDragLeaveEvent * pEvent )
{
int foo = 42;
}
void DragDropTest::dropEvent( QDropEvent * pEvent )
{
int foo = 42;
}
// main.cpp
#include "dragdroptest.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
DragDropTest w;
w.show();
return a.exec();
}