[vtkusers] Question key conversion in QVTKRenderWindowInteractor.keyPressEvent

Elvis Stansvik elvis.stansvik at orexplore.com
Thu Jun 16 04:55:44 EDT 2016


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()

    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/523874fd/attachment.html>


More information about the vtkusers mailing list