[vtkusers] Using vtkRenderWindow with QGraphicsView [Qt 4.4.1]

clinton at elemtech.com clinton at elemtech.com
Thu Aug 28 17:02:46 EDT 2008


On Thursday 28 August 2008 1:07:27 pm Prashanth Udupa wrote:
> Hi Clinton,
>
> I would recommend implementing a QPaintEngine for the QVTKWidget, instead
> of
>
> > what you're trying to do.  Then it should simply be a matter of setting a
> > QVTKWidget as the viewport of the QGraphicsView.
>
> Hmmm... I did try something like that. I have a working vtkQtRenderWindow
> for Qt 4.4; which we can set as viewport for QGraphicsView. But then I
> wonder if the paintGL() of the viewport would blend well with the
> paint-sequence of graphics view. I mean we would have two potential
> painting sequences
>
> - The viewport's paintGL() method
> - QGraphicsView's drawBackground(), scene()->render() and drawForeground()
>
> When we setViewport() another widget to QGraphicsView, we are basically
> allowing QGraphicsView to deal with all events delivered to the viewport.
>
> void QAbstractScrollArea::setViewport(QWidget *widget)
> {
>         // .........
>         d->viewport->installEventFilter(d->viewportFilter);
>         // .........
> }
>
> The viewportFilter sends all events from the viewport to the
> QAbstractScrollArea::viewportEvent(), which would essentially call event
> handlers in QGraphcisView to handle the event. This means that paintEvent
> of the viewport, will be handled in the paintEvent() of QGraphicsView. This
> means that the first paint-sequence (aka QGLWidget::paintGL()) will never
> be called.
>
> Which is why I think we should do the painting in drawBackground(), which
> is a part of the second painting sequence; the one that actually gets
> executed.

I agree as well.  Its the QGraphicsScene::drawBackground that should do the 
equivalent of QGLWidget::paintGL().  At least that's the impression I get 
when reading about this in the recent "Qt Quarterly" newsletter.  If VTK were 
involved, that means vtkRenderWindow::Render gets called from 
QGraphicsScene::drawBackground.  Any other drawing done by other functions 
gets overlayed on the Window using the paint engine provided with the 
QVTKWidget.

>
>
> I've done some experimenting with a QPaintEngine for QVTKWidget before, but
>
> > I
> > haven't done enough to get something to commit into the repository.  Do
> > you want some of that code to play with too?
>
> Thanks, that would be great :). You could send it to me or post it to the
> list.

See the source attached.  Where it uses a subclass of QVTKWidget as the 
viewport of the QGraphicsView.  Its not perfect, but its probably a good 
start.  For now, it just paints a QPixmap into the viewport with a VTK scene.

Clint
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cxx
Type: text/x-c++src
Size: 6291 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080828/b5ab29bb/attachment.cxx>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 6051 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080828/b5ab29bb/attachment.png>


More information about the vtkusers mailing list