[vtkusers] Key events in QVTKWidget2

Rakesh Patil rakesh.p at tataelxsi.co.in
Tue Sep 27 11:20:56 EDT 2016


Hi,


In order to check what is blocking Key events I compared QVTKWidget & QVTKWidget2 source files. I found the following line in QVTKWidget:


this->setFocusPolicy(Qt::StrongFocus);


And this was missing in QVTKWidget2. Is there any specific reason as why it was removed from QVTKWidget2? By adding this statement in my application, key events are working.


Warm Regards

Rakesh Patil

________________________________
From: vtkusers <vtkusers-bounces at vtk.org> on behalf of Rakesh Patil <rakesh.p at tataelxsi.co.in>
Sent: Monday, September 26, 2016 7:13:15 PM
To: vtkusers at vtk.org
Subject: [vtkusers] Key events in QVTKWidget2


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/20160927/fc235852/attachment.html>


More information about the vtkusers mailing list