[vtkusers] GetKeySym and GetKeyCode for QVTKRenderWindowInteractor
David Gobbi
david.gobbi at gmail.com
Thu Aug 28 18:14:07 EDT 2014
Hi Greg,
I looked through QVTKRenderWindowInteractor.py and discovered
this in its keyPressEvent() method:
self._Iren.SetEventInformationFlipY(self.__saveX, self.__saveY,
ctrl, shift, key, 0, None)
Compare this with the arguments that the method expects
(in vtkRenderWindowInteractor.h):
void SetEventInformationFlipY(int x, int y, int ctrl, int shift,
char keycode, int repeatcount, const char* keysym)
As you can see, the author of this class was a bit lazy and passed
None as the keysym, instead of getting the keysym from Qt and
then passing it through to VTK. But to be fair, this code was written
twelve years ago and maybe keysyms weren't the highest priority.
If you can patch QVTKRenderWindowInteractor.py so that it passes
the keysym strings from Qt to "self._Iren", then I can add your patch
to the VTK master.
- David
On Thu, Aug 28, 2014 at 3:49 PM, Greg Schussman
<greg.schussman at gmail.com> wrote:
> Oops.
>
> I forgot to mention that I'm using python-2.6, vtk-5.10.1, and qt-4.6.1.
>
> Greg
>
>
>
> On Thu, Aug 28, 2014 at 2:14 PM, Greg Schussman <greg.schussman at gmail.com>
> wrote:
>>
>> Hi.
>>
>> I've got a working python vtk demo that uses a vtkRenderWindowInteractor,
>> with the style set to vtkInteractorStyleTrackballCamera. I run into a
>> problem when I try to embed this in Qt.
>>
>> I use interactor.AddObserver('KeyPressEvent', key_handler) to see key
>> presses and act on them.
>>
>> In my key_handler function, I query the interactor (passed in as an
>> argument to key_handler) about which key was pressed.
>>
>> In my working example:
>>
>> when I press 'b',
>> interactor.GetKeyCode() gives 'b', and
>> interactor.GetKeySym() give 'b'.
>>
>> when I press esc,
>> interactor.GetKeyCode() gives an unprintable character, and
>> interactor.GetKeySym() gives 'Escape'.
>>
>> In my non-working Qt example, I use QVTKRenderWindowInteractor(frame)
>> instead (copied from the VTK/Examples/Python/Widgets/EmbedPyQt example).
>>
>> now, when I press 'b',
>> interactor.GetKeyCode() gives 'b', and
>> interactor.GetKeySym() gives None.
>>
>> when I press esc,
>> interactor.GetKeyCode() gives an unprintable character, and
>> interactor.GetKeySym() gives None.
>>
>> So, originally, I used GetKeySym(), but when switching to the
>> QVTKRenderWindowInteractor, that stopped working (always returning None).
>> I'm concerned about possible inconsistencies from one linux machine to
>> another when using GetKeyCode, so I'm reluctant to use it.
>>
>> What should I do here? Is there any reason why the
>> QTVTKRenderWindowInteractor would be giving None for the KeySym?
>>
>> For what it's worth, my demo code runs both with regular vtk and embedded
>> in pyqt, and the mouse interaction is fine, and the '3' option does toggle
>> stereo in both cases. But for some reason my observer can see the key with
>> GetKeySym in regular vtk mode, but not in embedded pyqt mode.
>>
>> Thanks in advance for any help or suggestions.
>>
>> Greg
More information about the vtkusers
mailing list