[vtkusers] Drag and Drop Issues with QVTKWidget

clinton at elemtech.com clinton at elemtech.com
Mon Mar 12 14:40:52 EDT 2007


> I am attempting to get Drag n' Drop support working for a subclass of
> QVTKWidget that I use in a project.  I have reimplemented the
> dragEnterEvent() and dropEvent() methods as per Qt instructions.
> Nothing happens.  I dropped a qDebug call into the top of both those
> methods and can confirm that they are simply not being called.
> AcceptDrops is set to true and everything that I can think of is set
> up properly?  Has anyone successfully set up DnD with QVTKWidget? If
> so, how?

It works fine for me in Qt 4.

Here's what I did, make myvtkwidget.h in VTK/Examples/GUI/Qt/Events (see 
header below)
Then in the Qt designer promote the QVTKWidgets to MyQVTKWidget.
Compile then run the events example.  I dragged something from my desktop and 
dropped it on one of the MyQVTKWidgets and I got the print outs I expected.

Clint


===============================
#ifndef MyQVTKWidget_h
#define MyQVTKWidget_h

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

class MyQVTKWidget : public QVTKWidget
{
public:
  MyQVTKWidget(QWidget* p) : QVTKWidget(p)
    {
    this->setAcceptDrops(true);
    }
protected:
  void dragEnterEvent(QDragEnterEvent* e)
    {
    printf("got drag enter event %i\n", this->acceptDrops());
    e->acceptProposedAction();
    }
  void dropEvent(QDropEvent* e)
    {
    printf("got drop event\n");
    }
};

#endif //  MyQVTKWidget_h





More information about the vtkusers mailing list