[vtkusers] Question key conversion in QVTKRenderWindowInteractor.keyPressEvent

Elvis Stansvik elvis.stansvik at orexplore.com
Thu Jun 16 04:59:20 EDT 2016


2016-06-16 10:55 GMT+02:00 Elvis Stansvik <elvis.stansvik at orexplore.com>:

> In QVTKRenderWindowInteractor, keyPressEvent and keyReleaseEvent are
> implemented as follows:
>
>     def keyPressEvent(self, ev):
>         ctrl, shift = self._GetCtrlShift(ev)
>         if ev.key() < 256:
>             key = str(ev.text())
>         else:
>             key = chr(0)
>
>         keySym = _qt_key_to_key_sym(ev.key())
>         if shift and len(keySym) == 1 and keySym.isalpha():
>             keySym = keySym.upper()
>
>         self._Iren.SetEventInformationFlipY(self.__saveX, self.__saveY,
>                                             ctrl, shift, key, 0, keySym)
>         self._Iren.KeyPressEvent()
>         self._Iren.CharEvent()
>

Also, why deliver both a KeyPressEvent and CharEvent here? Is that a clue
to why str(ev.text()) is used perhaps?

Elvis



>     def keyReleaseEvent(self, ev):
>         ctrl, shift = self._GetCtrlShift(ev)
>         if ev.key() < 256:
>             key = chr(ev.key())
>         else:
>             key = chr(0)
>
>         self._Iren.SetEventInformationFlipY(self.__saveX, self.__saveY,
>                                             ctrl, shift, key, 0, None)
>         self._Iren.KeyReleaseEvent()
>
> Notice how in keyPressEvent, key (the keycode passed to
> SetEventInformationFlipY) is constructed from str(ev.text()), which I find
> strange. Why use the .text() of the Qt event and not the keycode (.key())?
> SetEventInformationFlipY seems to expect a char a keycode.
>
> In keyReleaseEvent it is constructed from chr(ev.key()), which I think
> looks right.
>
> Is there some subtility I'm missing here, or is this just a mistake?
>
> Thanks in advance,
> Elvis
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160616/66b686d4/attachment.html>


More information about the vtkusers mailing list