[Interest] Press and hold keyboard key to bring up menu in QML

Elvis Stansvik elvstone at gmail.com
Fri Apr 1 17:06:28 CEST 2016

2016-04-01 16:11 GMT+02:00 Reinhardt Behm <rbehm at hushmail.com>:
> On Friday 01 April 2016 14:33:29 Elvis Stansvik wrote:
>> 2016-04-01 12:45 GMT+02:00 Elvis Stansvik <elvstone at gmail.com>:
>> > Hi folks,
>> >
>> > I have a full screen, page based Qt Quick 2 application. Input is
>> > contstrained by the hardware to the Left/Right/Return keyboard keys,
>> > so is quite limited, and navigation between pages is done using
>> > buttons on each page which handle return presses using (most of the
>> > time) Keys.onReturnPressed and navigation between buttons and other
>> > items with KeyNavigation.left/right.
>> >
>> > I now have the need to provide a special global shortcut: On almost
>> > all of the screens, holding the Enter key for 3 seconds should bring
>> > the user immediately to a sort of start screen, where he/she can
>> > choose to go into Settings or Power Off. Kind of like how holding the
>> > power button on a phone often brings up a power off/flight mode menu.
>> >
>> > I'm struggling to find a good way to handle this centrally: since
>> > Enter presses are normally accepted (swallowed) by my various buttons
>> > and other input items on the pages, where can I put some central key
>> > press/release handler in which to start/stop a timer (to determine if
>> > it was a long 3 sec press or not)?
>> >
>> > My pages are FocusScopes stuffed in a StackView inside a Window.
>> >
>> > Many thanks for any advice. Has noone had this kind of requirement
>> > before? (Global "hold key" shortcut).
>> Actually, scratch this. Our input device is a pushable wheel, and I've
>> realized now that we better re-program the Arduino we have hooked up
>> to it to have the logic to determine "long" vs "short" presses there
>> instead, and deliver these as distinct keypresses.
> Well this might be the better idea.
> I don't know enough about Qt Quick since I am doing everything in C++ and
> widgets. But there I would install an event filter on every page, catching
> keypress/release for the enter key, but no eating it up. Start a QTimer on
> press, stop it on release. If it fires, enter was pressed long and this can
> trigger your global action.

Yes, this is sort of what I started doing, but couldn't quite find an
equivalent of an event filter.

But I think in the end, modifying the code on the Arduino hooked up to
the pushwheel is what we'll do.


> Reinhardt
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

More information about the Interest mailing list