[vtkusers] QVTKWidget paintEvent

(Samuel) Byeongjun Park byeongjun.park at case.edu
Mon Sep 27 14:17:59 EDT 2010


> 1) The mouse events are not catched by the interactor of
> vtkImageViewer2. I mean, when I drag the mouse, it should do
> window/level and after subclassing the mousePress/mouseRelease and
> mouseMove events, it doesn't work anymore.

In your inherited mousePressEvent()
You have to call the parent's mousePressEvent() explicitly.

Void myWidget::mousePressEvent(QMouseEvent *pEvent)
{
  ...
   QVTKWidget::mousePressEvent(pEvent);
  ...
   This->update();
}

> 2) My drawing is flicking over the background image viewer, is there a
> way to avoid flickering?.

That problem caused by either of several problems.
I suspect you put every drawing code in paintEvent().
You would better not to do that. Please consider to draw on some other
canvas widget (i.e. QPixmap)
Only when you need to change the drawing. And in paintEvent(), just copy
them to the visible window. 
It reduces flickering.

Sam.

-----Original Message-----
From: Leonardo M. Ramé [mailto:l.rame at griensu.com] 
Sent: Monday, September 27, 2010 10:51 AM
To: (Samuel) Byeongjun Park
Cc: 'VTK Users'
Subject: Re: [vtkusers] QVTKWidget paintEvent

Thanks Sam, I tried this, but found two problems:

1) The mouse events are not catched by the interactor of
vtkImageViewer2. I mean, when I drag the mouse, it should do
window/level and after subclassing the mousePress/mouseRelease and
mouseMove events, it doesn't work anymore.

2) My drawing is flicking over the background image viewer, is there a
way to avoid flickering?.

-- 
Leonardo M. Ramé
http://leonardorame.blogspot.com

On 2010-09-24 10:32:15 -0400, (Samuel) Byeongjun Park wrote:
> You have to override the mouse events in your myWidget class,
> such as mousePressEvent(), mouseMoveEvent(), mouseReleaseEvent(),
> wheelEvent() and etc.
> and call update() there.
> If the painting job is heavy stuff, you would better to make conditional
> painting routine or merge them into VTK's rendering process using
> vtkPolyData (maybe with vtkCutter).
> 
> Sam.
> 
> -----Original Message-----
> From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On Behalf
> Of Leonardo M. Rame
> Sent: Friday, September 24, 2010 9:53 AM
> To: VTK Users
> Subject: [vtkusers] QVTKWidget paintEvent
> 
> Hi, can paint over a QVTKWidget, however my drawings are lost when I
> click on the widget or after setting a vtkImageViewer2 into it.
> 
> This is the code I use to paint over the QVTKWidget:
> 
> QPaintEngine * myWidget::paintEngine() const
> {
>   return QWidget::paintEngine();
> }
> 
> void myWidget::paintEvent(QPaintEvent * e)
> {
>   QVTKWidget::paintEvent(e);
>   QPainter paint(this);
>   paint.setPen(Qt::white);
>   paint.drawRect(5,5,10,10);
> }
> 
> How can I let my drawings repaint over the image viewer
> 
> -- 
> Leonardo M. Ramé
> http://leonardorame.blogspot.com
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers






More information about the vtkusers mailing list