[vtkusers] GetKeySym and GetKeyCode for QVTKRenderWindowInteractor

Greg Schussman greg.schussman at gmail.com
Fri Aug 29 13:59:30 EDT 2014


Hi, David.

Thanks for the speedy reply.

On looking closer, it appears to me that Qt doesn't exactly provide keysym
strings.  there is a .text() function, but that's already being used for
key. Using it for keysym as well, would work for the 'a' to 'z' keys, but
not for keys such as 'Escape'.

Now, I see a qt_key_to_key_sym(Qt::Key) function defined in
GUISupport/Qt/QVTKInteractorAdapter.cxx.  This appears to do exactly what
we want (converting a Qt key to a vtk keysym), but I'm not clear on how to
call it from python.

If you can provide a hint to get me unstuck here, I'd be happy to provide
that patch.

Thanks again.

Greg



On Thu, Aug 28, 2014 at 3:14 PM, David Gobbi <david.gobbi at gmail.com> wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20140829/5ebbad38/attachment.html>


More information about the vtkusers mailing list