[vtkusers] vtkImageInteractorStyle and MouseWheelEvent
Romain LEGUAY
romain.leguay at gmail.com
Thu Dec 6 14:46:22 EST 2018
Hi everyone,
I try to use the mouse wheel on a vtkResliceImageViewer in a Qt window.
I try to add a callback to the vtkImageInteractorStyle like this:
QtVTKExample::QtVTKExample(QWidget *parent) : QWidget(parent)
{
m_layout = new QVBoxLayout;
m_window = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
m_widget = new QVTKOpenGLWidget(this);
m_widget->SetRenderWindow(m_window);
m_image = vtkSmartPointer<vtkImageData>::New();
m_mapper = vtkSmartPointer<vtkImageResliceMapper>::New();
m_mapper->SetInputData(m_image);
m_viewer = vtkSmartPointer<vtkResliceImageViewer>::New();
m_viewer->SetRenderWindow(m_window);
m_viewer->SetupInteractor(m_window->GetInteractor());
m_viewer->GetImageActor()->SetMapper(m_mapper);
addObservers();
m_layout->addWidget(m_widget);
setLayout(m_layout);
}
void WheelBackwardFunction (vtkObject*, long unsigned int, void*, void*)
{
std::cout << "wheel backward" << std::endl;
}
void WheelForwardFunction (vtkObject*, long unsigned int, void*, void*)
{
std::cout << "wheel forward" << std::endl;
}
void QtVTKExample::addObservers()
{
m_wheelForward = vtkSmartPointer<vtkCallbackCommand>::New();
m_wheelBackward = vtkSmartPointer<vtkCallbackCommand>::New();
m_wheelForward->SetCallback(WheelForwardFunction);
m_wheelBackward->SetCallback(WheelBackwardFunction);
m_viewer->GetInteractorStyle()->AddObserver(vtkCommand::MouseWheelForwardEvent, m_wheelForward);
m_viewer->GetInteractorStyle()->AddObserver(vtkCommand::MouseWheelBackwardEvent, m_wheelBackward);
}
The window opens, with no warnings but the callback function are never called.
What did I do wrong?
Thank you,
Romain
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20181206/18e7c21c/attachment.html>
More information about the vtkusers
mailing list