PDA

View Full Version : Drag & Drop is not activated in subclass of qdialog



K.Sasikala
12th September 2012, 10:26
cannn't activate the drag & drop event in a subclass of qdialog. please help me.

Ashkan_s
12th September 2012, 19:26
Have you used setAcceptDrops(true) to enable it? QWidget::setAcceptDrops()

Also you must re-implement dragEnterEvent() and accept the event. QWidget::dragEnterEvent()

Example:

dialog.h

#include <QDialog>

class dialog : public QDialog
{
Q_OBJECT
public:
explicit dialog(QWidget *parent = 0);

signals:

public slots:

protected:
void dragEnterEvent(QDragEnterEvent *event);

};

dialog.cpp

#include "dialog.h"
#include <QDragEnterEvent>

dialog::dialog(QWidget *parent) :
QDialog(parent)
{
setAcceptDrops(true);
}

void dialog::dragEnterEvent(QDragEnterEvent *event)
{
event->accept();
}

main.cpp

#include <dialog.h>
#include <QtGui>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

dialog d;

d.show();
return app.exec();
}


To view other related methods you can refer to dnd.html