[Interest] OS X Qt 5.2/5.3 keyboard modifier bug

Paul Miller paul at fxtech.com
Fri Apr 4 17:17:15 CEST 2014


On 4/4/2014 10:01 AM, Etienne Sandré-Chardonnal wrote:
> Do you have mouse tracking enabled on this widget? Otherwise you can't
> detect when the mouse enters the widget.
> I'm not sure that you implement it the proper way. Changing the mouse
> cursor when a modifier key (eg Ctrl) il pressed should not be done with
> the widget keyPressEvent, as this will not work if the user presses the
> key when the mouse is outside, then enters the widget. Also,
> keyPressEvent only works with focus, which is not what you want.

Yes, mouse-tracking is enabled. It's a viewer type widget with 
direct-manipulation stuff. I call setFocus() when I get mouseMove 
events. Once I click in the widget, it starts working as expected.

> I would suggest capturing the key presses at an upper level (such as the
> MainWindow) and change the child widget mouse cursor accordingly with
> setCursor. This way, the behavior is independant from focus, does not
> require mouse tracking, and does not require the cursor to be over the
> widget when the key is pressed.

The thing is the cursor should only change when the mouse is in the 
window, since it's related to direct manipulation of objects in the 
widget, not elsewhere in the UI, so I believe my current workflow is 
correct. Trapping the modifier at a higher level would break 
encapsulation as well.

Whether it's "right" or "wrong", this code has worked for 10 years, and 
broke in 5.x.

>
> Etienne
>
>
> 2014-04-04 16:20 GMT+02:00 Paul Miller <stelefx at gmail.com
> <mailto:stelefx at gmail.com>>:
>
>     Here is another regression I found that is a show-stopper for us.
>
>     In a custom widget I have a keyPressEvent() and keyReleaseEvent()
>     handler to update a cursor when modifier keys are pressed (such as Cmd).
>     In Qt 5.x, pressing Cmd (or shift, or ctrl) causes no keyPressEvents
>     UNTIL the user clicks on the widget. Manually calling setFocus() on the
>     widget when the mouse enters it doesn't help either.
>
>     This all worked before 5.x.
>
>     I can't be the only one to find this can I?
>     _______________________________________________
>     Interest mailing list
>     Interest at qt-project.org <mailto:Interest at qt-project.org>
>     http://lists.qt-project.org/mailman/listinfo/interest
>
>




More information about the Interest mailing list