[Qt-interest] [vtkusers] QT and VTK interactor how to manage the signals

Enrico Ros enrico.qt at email.it
Tue Mar 2 17:14:45 CET 2010


On Tuesday 02 March 2010 16:19:37 Giancarlo Amati wrote:
> Hi Clinton,
> thanks a lot for the answer. I just would like to make an example.
> Let's say that if I have a QVTKWidget in my QT interface and I press W on
> the keyword, that event is detected by QT (first) which forward it to the
> QVTKWidget and then the interactor. is that right?
> 
> So I wonder, if I make QT managing the press of W first and then I would
> like QVTKWidget doing whatever is programmed to do, would it be enough to
> add the correspondent handler in my QT Class (whatever it is? )
> 
> Thanks
> Giancarlo


Hello Giancarlo, here is an example that may be useful to you:

1. when initializing the widget, connect to the signal you want 

// connect Vtk Events to Qt Slots
m_connections = vtkEventQtSlotConnect::New();

// get key pressed with high priority (1.0)
m_connections->Connect(m_widget->GetRenderWindow()->GetInteractor(), 
vtkCommand::KeyPressEvent, target, SLOT(slotKeyPressed(vtkObject*, unsigned 
long, void*, void*, vtkCommand*)), 0, 1.0); // <-notice the 1.0

2. in your slot:

void Target::slotKeyPressed(vtkObject *, unsigned long, void *, void *, 
vtkCommand *command)
{
    if ( doSomething() ) {
        // consume event so the interactor doesn't get it
        command->AbortFlagOn();
    }
}

So you can handle the key press and you're the first to do so (1.0) and if you 
want to stop the Interactor from getting the event, you can do it by calling 
AbortFlagOn();

Does this solve your problems?

Ciao,
Enrico Ros



More information about the Qt-interest-old mailing list