[vtkusers] Key events in QVTKWidget2
Rakesh Patil
rakesh.p at tataelxsi.co.in
Mon Sep 26 09:43:15 EDT 2016
Hi,
I would like to know how the events are propogated in case of QVTKWidget & QVTKWidget2. Is there any difference in these two? I have an application built with QVTKWidget. I have Graphics window derived from QVTKWidget
#ifndef GRAPHICSWINDOW_H
#define GRAPHICSWINDOW_H
#include <QWidget>
#include "QVTKWidget.h"
#include <vtkRenderer.h>
class GraphicsWindow : public QVTKWidget
{
Q_OBJECT
vtkRenderer *currentRenderer;
public:
GraphicsWindow(QWidget *parent = NULL);
~GraphicsWindow();
protected:
virtual void keyPressEvent(QKeyEvent *event);
virtual void keyReleaseEvent(QKeyEvent *event);
};
#endif
The definition for this class is as follows:
GraphicsWindow::GraphicsWindow(QWidget *parent)
:QVTKWidget(parent)
{
#ifdef QT_DEBUG
vtkObject::GlobalWarningDisplayOn();
#else
vtkObject::GlobalWarningDisplayOff();
#endif
currentRenderer = vtkRenderer::New();
currentRenderer->SetBackground( 0.5, 0.0, 0.0);
// vtkGenericOpenGLRenderWindow *glrw = vtkGenericOpenGLRenderWindow::SafeDownCast(this->GetRenderWindow());
// glrw->AddRenderer(currentRenderer);
// this->SetRenderWindow(glrw);
this->GetRenderWindow()->AddRenderer(currentRenderer);
this->GetRenderWindow()->GetInteractor()->SetInteractorStyle(currentInteractorStyle);
vtkSmartPointer<vtkCubeSource> cubeSource =
vtkSmartPointer<vtkCubeSource>::New();
cubeSource->SetCenter(10, 10, 10);
cubeSource->SetXLength(10);
cubeSource->SetYLength(10);
cubeSource->SetZLength(30);
cubeSource->Update();
vtkSmartPointer<vtkDataSetMapper> cubeMapper =
vtkSmartPointer<vtkDataSetMapper>::New();
cubeMapper->SetInputConnection(cubeSource->GetOutputPort());
vtkActor *cubeActor = vtkActor::New();
cubeActor->SetMapper(cubeMapper);
cubeActor->GetProperty()->SetRepresentationToWireframe();
cubeActor->GetProperty()->LightingOff();
cubeActor->GetProperty()->SetColor(1, 1, 1);
currentRenderer->AddActor(cubeActor);
}
GraphicsWindow::~GraphicsWindow()
{
}
void GraphicsWindow::keyPressEvent(QKeyEvent *event)
{
std::cout << "Key press" << std::endl;
}
void GraphicsWindow::keyReleaseEvent(QKeyEvent *event)
{
std::cout << "Key release" << std::endl;
}
When this application is built with QVTKWidget, the keypress and keyrelease events are executing fine. But when the same code built with QVTKWidget2 there key events are not processed. Is there any differences in these two widgets? Is there anything wrong I am doing? Kindly guide me as to how to process key events using QVTKWidget2.
Thanks
Warm Regards
Rakesh Patil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160926/5101d58c/attachment.html>
More information about the vtkusers
mailing list