<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Hi,</p>
<p><br>
</p>
<p>In order to check what is blocking Key events I compared QVTKWidget & QVTKWidget2 source files. I found the following line in QVTKWidget:</p>
<p><br>
</p>
<p><span class="pl-v" style="box-sizing: border-box; color: rgb(237, 106, 67); font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; white-space: pre;">this</span><span style="color: rgb(51, 51, 51); font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; white-space: pre;">-></span><span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179); font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; white-space: pre;">setFocusPolicy</span><span style="color: rgb(51, 51, 51); font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 12px; line-height: 20px; white-space: pre;">(Qt::StrongFocus);</span></p>
<p><br>
</p>
<p>And this was missing in QVTKWidget2. Is there any specific reason as why it was removed from <span style="font-family: Calibri, Arial, Helvetica, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;">QVTKWidget2</span>?
 By adding this statement in my application, key events are working. </p>
<p><br>
</p>
<div id="Signature">
<div id="divtagdefaultwrapper" style="font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif">
<p>Warm Regards</p>
<p>Rakesh Patil</p>
<p></p>
</div>
</div>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> vtkusers <vtkusers-bounces@vtk.org> on behalf of Rakesh Patil <rakesh.p@tataelxsi.co.in><br>
<b>Sent:</b> Monday, September 26, 2016 7:13:15 PM<br>
<b>To:</b> vtkusers@vtk.org<br>
<b>Subject:</b> [vtkusers] Key events in QVTKWidget2</font>
<div> </div>
</div>
<div>
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Hi,</p>
<p><br>
</p>
<p>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</p>
<p><br>
</p>
<p></p>
<pre style="margin-top: 0px; margin-bottom: 0px;"><!--StartFragment--><span style=" color:#000080;">#ifndef</span><span style=" color:#c0c0c0;"> </span>GRAPHICSWINDOW_H</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#000080;">#define</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">GRAPHICSWINDOW_H</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#000080;">#include</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;"><QWidget></span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#000080;">#include</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">"QVTKWidget.h"</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#000080;">#include</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;"><vtkRenderer.h></span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#808000;">class</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">GraphicsWindow</span><span style=" color:#c0c0c0;"> </span>:<span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">public</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">QVTKWidget</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;">{</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#000080;">Q_OBJECT</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">vtkRenderer</span><span style=" color:#c0c0c0;"> </span>*<span style=" color:#800000;">currentRenderer</span>;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#808000;">public</span>:</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">GraphicsWindow</span>(<span style=" color:#800080;">QWidget</span><span style=" color:#c0c0c0;"> </span>*parent<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">NULL</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>~<span style="font-style: italic;">GraphicsWindow</span>();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#808000;">protected</span>:</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#808000;">virtual</span><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">void</span><span style=" color:#c0c0c0;"> </span><span style="font-style: italic;">keyPressEvent</span>(<span style=" color:#800080;">QKeyEvent</span><span style=" color:#c0c0c0;"> </span>*event);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#808000;">virtual</span><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">void</span><span style=" color:#c0c0c0;"> </span><span style="font-style: italic;">keyReleaseEvent</span>(<span style=" color:#800080;">QKeyEvent</span><span style=" color:#c0c0c0;"> </span>*event);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;">};</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#000080;">#endif</span><span style=" color:#c0c0c0;"> </span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"><br></span></pre>
The definition for this class is as follows:
<div><br>
</div>
<div>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#800080;">GraphicsWindow</span>::GraphicsWindow(<span style=" color:#800080;">QWidget</span><span style=" color:#c0c0c0;"> </span>*parent)</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>:<span style=" color:#800080;">QVTKWidget</span>(parent)</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;">{</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#000080;">#ifdef</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">QT_DEBUG</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">vtkObject</span>::GlobalWarningDisplayOn();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#000080;">#else</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>vtkObject::GlobalWarningDisplayOff();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#000080;">#endif</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#800000;">currentRenderer</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">vtkRenderer</span>::New();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#800000;">currentRenderer</span>-><span style="font-style: italic;">SetBackground</span>(<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">0.5</span>,<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">0.0</span>,<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">0.0</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#008000;">//</span><span style=" color:#c0c0c0;">    </span><span style=" color:#008000;">vtkGenericOpenGLRenderWindow</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">*glrw</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">=</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">vtkGenericOpenGLRenderWindow::SafeDownCast(this->GetRenderWindow());</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#008000;">//</span><span style=" color:#c0c0c0;">    </span><span style=" color:#008000;">glrw->AddRenderer(currentRenderer);</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#008000;">//</span><span style=" color:#c0c0c0;">    </span><span style=" color:#008000;">this->SetRenderWindow(glrw);</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#808000;">this</span>-><span style="font-style: italic;">GetRenderWindow</span>()-><span style="font-style: italic;">AddRenderer</span>(<span style=" color:#800000;">currentRenderer</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#808000;">this</span>-><span style="font-style: italic;">GetRenderWindow</span>()-><span style="font-style: italic;">GetInteractor</span>()-><span style="font-style: italic;">SetInteractorStyle</span>(<span style=" color:#800000;">currentInteractorStyle</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">vtkSmartPointer</span><<span style=" color:#800080;">vtkCubeSource</span>><span style=" color:#c0c0c0;"> </span>cubeSource<span style=" color:#c0c0c0;"> </span>=</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">            </span><span style=" color:#800080;">vtkSmartPointer</span><<span style=" color:#800080;">vtkCubeSource</span>>::New();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>cubeSource-><span style="font-style: italic;">SetCenter</span>(<span style=" color:#000080;">10</span>,<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">10</span>,<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">10</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>cubeSource-><span style="font-style: italic;">SetXLength</span>(<span style=" color:#000080;">10</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>cubeSource-><span style="font-style: italic;">SetYLength</span>(<span style=" color:#000080;">10</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>cubeSource-><span style="font-style: italic;">SetZLength</span>(<span style=" color:#000080;">30</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>cubeSource-><span style="font-style: italic;">Update</span>();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">vtkSmartPointer</span><<span style=" color:#800080;">vtkDataSetMapper</span>><span style=" color:#c0c0c0;"> </span>cubeMapper<span style=" color:#c0c0c0;"> </span>=</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">            </span><span style=" color:#800080;">vtkSmartPointer</span><<span style=" color:#800080;">vtkDataSetMapper</span>>::New();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>cubeMapper-><span style="font-style: italic;">SetInputConnection</span>(cubeSource->GetOutputPort());</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">vtkActor</span><span style=" color:#c0c0c0;"> </span>*cubeActor<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">vtkActor</span>::New();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>cubeActor-><span style="font-style: italic;">SetMapper</span>(cubeMapper);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>cubeActor->GetProperty()->SetRepresentationToWireframe();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#008000;"></span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>cubeActor->GetProperty()-><span style="font-style: italic;">LightingOff</span>();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#008000;"></span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>cubeActor->GetProperty()-><span style="font-style: italic;">SetColor</span>(<span style=" color:#000080;">1</span>,<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">1</span>,<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">1</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#008000;"></span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#800000;">currentRenderer</span>->AddActor(cubeActor);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style="font-family: Calibri, Arial, Helvetica, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 12pt;">}</span><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#800080;">GraphicsWindow</span>::~<span style="font-style: italic;">GraphicsWindow</span>()</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;">{</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;">}</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#808000;">void</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">GraphicsWindow</span>::<span style="font-style: italic;">keyPressEvent</span>(<span style=" color:#800080;">QKeyEvent</span><span style=" color:#c0c0c0;"> </span>*event)</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;">{</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">std</span>::cout<span style=" color:#c0c0c0;"> </span><<<span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">"Key</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">press"</span><span style=" color:#c0c0c0;"> </span><<<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">std</span>::endl;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;">}</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#808000;">void</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">GraphicsWindow</span>::<span style="font-style: italic;">keyReleaseEvent</span>(<span style=" color:#800080;">QKeyEvent</span><span style=" color:#c0c0c0;"> </span>*event)</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;">{</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">std</span>::cout<span style=" color:#c0c0c0;"> </span><<<span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">"Key</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">release"</span><span style=" color:#c0c0c0;"> </span><<<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">std</span>::endl;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;">}</pre>
<br>
<p></p>
<p>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.</p>
<p><br>
</p>
<p>Thanks</p>
<p><br>
</p>
<div id="Signature">
<div id="divtagdefaultwrapper" style="font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif">
<p>Warm Regards</p>
<p>Rakesh Patil</p>
<p></p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>