[vtkusers] Question key conversion in QVTKRenderWindowInteractor.keyPressEvent
Elvis Stansvik
elvis.stansvik at orexplore.com
Thu Jun 16 10:48:25 EDT 2016
2016-06-16 16:32 GMT+02:00 David Gobbi <david.gobbi at gmail.com>:
> On Thu, Jun 16, 2016 at 7:33 AM, Elvis Stansvik <
> elvis.stansvik at orexplore.com> wrote:
>
>>
>> So that fix was indeed correct, and from the Qt docs for key():
>>
>> "Note that this function does not distinguish between capital and
>> non-capital letters, use the text
>> <http://doc.qt.io/qt-5/qkeyevent.html#text>() function (returning the
>> Unicode text the key generated) for this purpose."
>>
>> So I guess keyReleaseEvent should be changed to also use str(ev.text()).
>> But thinking more about how Qt's key() is used in
>> QVTKRenderWindowInteractor, for example:
>>
>> if ev.key() < 256:
>> ...
>>
>> Is it not wrong to make assumptions about the .key() as a number like
>> this? I don't think Qt gives any guarantee that the Qt::Key enum values
>> correspond to ASCII values? (even if they currently do). Shouldn't the code
>> first call .text() and then check that it's a single byte string, instead
>> of making assumptions about the layout of the Qt::Key enum?
>>
>
> Yes, keyReleaseEvent should match keyPressEvent, the original author of
> the change must have missed that.
>
> If .text() returns a single character with a unicode code point < 256, it
> should be fine to use that as the VTK key code. Otherwise the VTK key code
> should be set to zero. VTK's key code is meant to correspond to the text
> produced by the key press.
>
Alright, yes that makes sense.
Elvis
>
> - David
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160616/e497e1ca/attachment.html>
More information about the vtkusers
mailing list