[vtkusers] Drag and Drop Issues with QVTKWidget

Ben Hughes ben at pixelmachine.org
Mon Mar 12 19:45:39 EDT 2007


Problem Solved: QVTKWidget cannot be the toplevel window if Drag n'
Drop functionality is desired.

Ben Hughes
On 3/12/07, Clinton Stimpson <clinton at elemtech.com> wrote:
> Do you mind posting an email to the vtk list to close the thread?
> Clint
>
> Ben Hughes wrote:
> > Excellent, I was just using my QVTKWidget as the toplevel window.
> > Thank you very much for helping me with this issue.
> >
> > Ben Hughes
> > On 3/12/07, clinton at elemtech.com <clinton at elemtech.com> wrote:
> >>
> >> Now I see it.  As a workaround for that case, give the QVTKWidget a
> >> QWidget
> >> parent.  You can set the layout margin to zero, so it looks like a
> >> top level
> >> window.
> >>
> >> In your real application, was the QVTKWidget a top level widget or not?
> >>
> >> I was also able to reproduce this on a top level QWidget by doing
> >> certain
> >> things to it.  I'll report this bug to Trolltech.
> >>
> >> Clint
> >>
> >> On Monday 12 March 2007 4:37 pm, Ben Hughes wrote:
> >> > I took your code and copied it into a header file then to make it go I
> >> > wrote the following code
> >> >
> >> > int main(int argc, char *argv[]) {
> >> >       QApplication app(argc, argv);
> >> >       MyQVTKWidget* widget = new MyQVTKWidget();
> >> >       widget->show();
> >> >       return app.exec();
> >> > }
> >> >
> >> > This handles DnD just fine.  I then attempt to add some utility to the
> >> > program by changing that to
> >> >
> >> > int main(int argc, char *argv[]) {
> >> >       QApplication app(argc, argv);
> >> >
> >> >       MyQVTKWidget* widget = new MyQVTKWidget();
> >> >       vtkRenderer* ren = vtkRenderer::New();
> >> >       widget->GetRenderWindow()->AddRenderer(ren);
> >> >       ren->SetBackground(.9, .2, .5);
> >> >       widget->show();
> >> >       return app.exec();
> >> > }
> >> >
> >> > At this point the drag n' drop stops working.
> >> >
> >> > Thanks,
> >> > Ben Hughes
> >> >
> >> > On 3/12/07, clinton at elemtech.com <clinton at elemtech.com> wrote:
> >> > > Are you are using something like a vtkWin32RenderWindowInteractor
> >> instead
> >> > > of the QVTKInteractor?
> >> > > Or are you doing something like vtkRenderWindowInteractor::New()
> >> > > anywhere?  Or are you using something like a vtkImageViewer where
> >> certain
> >> > > interactor setup is required to work with QVTKWidget?
> >> > >
> >> > > It works for me and others.  Unless I get more info, I don't know
> >> why it
> >> > > doesn't work for you.
> >> > >
> >> > > Clint
> >> > >
> >> > > On Monday 12 March 2007 4:01 pm, Ben Hughes wrote:
> >> > > > My further investigation indicates that this only works until a
> >> > > > vtkRenderWindow is added into the mix.  Once the
> >> vtkRenderWindow is
> >> > > > set, all DnD abilities die.  I am looking towards resolutions
> >> at this
> >> > > > time but will probably settle for a Drag n' Drop "dock" type
> >> widget
> >> > > > located below the rendering surface.
> >> > > >
> >> > > > Ben Hughes
> >> > > >
> >> > > > On 3/12/07, clinton at elemtech.com <clinton at elemtech.com> wrote:
> >> > > > > > 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
> >>
> >
> >
>
>


-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1.2
GAT d--(-) s: a--- C++++ UL++>$ P+ L+++>$ !E W+++$ N+ o? K- w--- O M+
V- PS+(++) PE Y++(+) PGP++ t+ 5 X-- R(+) tv b+(+++) DI+ D++ G e* h! r
!y
-----END GEEK CODE BLOCK-----



More information about the vtkusers mailing list