[vtkusers] flickering when using Qt with VTK

clinton at elemtech.com clinton at elemtech.com
Thu Nov 16 12:46:12 EST 2006


I would not use your approach of using Qt's QPainter in a VTK drawing area.  
On X11, if the window gets an expose event, you get an out of sync between 
Qt's buffers and VTK buffers, and VTK overwrites the Qt drawing you did.  I 
imagine the same would happen on Windows.  It doesn't work at all on the Mac, 
because Qt and OpenGL use entirely different buffers.

Try the attached code.  A QVTKWidget subclass observes a vtkRenderer's 
EndEvent.  It provides a buffer for your Qt drawing which you do in a virtual 
function you overload.  When your function returns, it composites your Qt 
drawing into VTK.  There is no flickering and it works on all platforms.

There are alternative approaches, but the ideas is either some form of 
compositing must happen, or Qt draws directly into VTK's OpenGL context.

Clint

On Thursday 16 November 2006 9:13 am, Anja Ende wrote:
> Hi Clint,
>
> I finally got around to putting together a trivial example that
> demonstrates the flicker problem.
>
> It is all in one simple file. I am attaching the source and the Qt .pro
> file with this mail. You might have to tweak the pro file to reflect the
> correct VTK path and you will have to change the input PNG file name in the
> main() function.
>
> So basically, the VTK part simply draws a PNG on screen and there is some
> Qt code drawing on top of it..
>
> So, if you click with the right mouse button it will add a point on the
> screen and there will be a line going through all the points that you have
> added. You can click with left mouse button on a point and move it. You
> will see that when a point is moved, the whole Qt rendered area flickers a
> lot. I think this is because VTK finishes painting and refreshes the screen
> and then Qt does it...
>
> Thank you so much for looking at it. I really appreciate it. If you run
> into problems with the code, please let me know.
>
> Forever grateful,
>
> Anja
>
> On 14/11/06, clinton at elemtech.com <clinton at elemtech.com> wrote:
> > Yeah, that's fine.  And we can do it offlist, and post the results to the
> > list
> > when we're done.
> >
> > Clint
> >
> > On Tuesday 14 November 2006 2:04 pm, you wrote:
> > > I think I can do that. May I send it to you tomorrow or day after?
> > >
> > > Thanks,
> > > Anja
> > >
> > > On 14/11/06, clinton at elemtech.com <clinton at elemtech.com> wrote:
> > > > > From: "Anja Ende" <anja.ende at googlemail.com>
> > > > > Subject: [vtkusers] flickering when using Qt with VTK
> > > > >
> > > > > Hi everyone,
> > > > >
> > > > > I am drawing on top of the VTK window using the painter methods in
> >
> > Qt.
> >
> > > > The
> > > >
> > > > > problem is that there is a lot of flickering during updates. So, I
> >
> > have
> >
> > > > > points that I can drag on the screen and this action causes a lot
> > > > > of flicker.
> > > > >
> > > > > Following an earlier discussion, I turned off double buffering (I
> > > > > am
> > > >
> > > > using
> > > >
> > > > > SuSE) by
> > > > >
> > > > > extern void qt_x11_set_global_double_buffer(bool);
> > > > > qt_x11_set_global_double_buffer(false);
> > > > >
> > > > > However, the flickering still persists. Has anyone else here
> > > >
> > > > successfully
> > > >
> > > > > done this? How did they avoid this flickering problem.
> > > > >
> > > > > Cheers,
> > > > >
> > > > > Anja
> > > >
> > > > Do you have a minimal example you can send me?
> > > >
> > > > Clint
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: text/x-c++src
Size: 2746 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061116/fafa6af6/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: QVTKOverlayWidget.h
Type: text/x-c++hdr
Size: 2986 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061116/fafa6af6/attachment.hpp>


More information about the vtkusers mailing list