Unsolved How to restrict the widget to only process events from a specific hardware input device?
-
I'm new to Qt so pardon me for asking dumb questions here. I have an embedded application here with two physical dials (the usb-powered PowerMate knobs) and in the GUI there are two corresponding dial widgets. The user interface usecase is such that the events (dial rotate clockwise/counter-clockwise, dial pressed/released) generated by physical dial 1 should be processed by dial widget1 only, and the events generated by physical dial 2 should be processed by dial widget 2 only. Is there a way to support this input-source-specific event processing in Qt?
-
Hi and welcome to devnet,
How are these devices handled by your system ?
Are they input like keyboard and mouse ? Do they provide SDKs to talk with them ?What OS are you on ?
What version of Qt are you using ? -
How are these devices handled by your system ?
I'm "thinking" of using device plug-in as described in this article: https://doc.qt.io/archives/qtextended4.4/tut-deviceexample.html
Are they input like keyboard and mouse ? Do they provide SDKs to talk with them ?
The powermate knob behaves like a mouse. When I plug it in the Linux kernel module "powermate" is loaded and I could see it in /dev/input/event5. Doing the "cat /dev/input/event5 | hexdump" and I can see the event data (timestamp, type, code, value).
What OS are you on ?
Ubuntu 16.04 VM for the cross compiling Qt
Wandboard for running the embedded applicationWhat version of Qt are you using ?
Qt5.8 -
Ok, does your system already reacts to these devices ?
-
No. I have yet to implement the plug-in yet. And I could not see in the plug-in examples how to implement the "handle-this-event-if-it-is-from-that-physical-input-device" feature?
My system (the Wandboard) does react to the powermate knob i.e. I connect the knob to the wandboard through the usb, and verify the /dev/input/event5 appears, and when I rotate the physical knob or press/release it I could see the event data with "cat /dev/input/event5 | hexdump".
-
Qt 5 uses a different architecture that Qt 4.
But I think you might have misunderstood my question. Are these device already handled by your desktop environment ? e.g. like a mouse.
-
If by "handled" you mean the corresponding Linux kernel module automatically loaded when I connect the powermate knob to the Wandboard then yes, the device is "handled" that way.
However if by "handled" you mean I can move the "cursor" around on the desktop then no, it is not "handled" by the desktop environment.
-
Good, then I'd recommend taking a look at this article about a custom QPlatformInputContext and this excellent KDAB post about the same subject.
-
Thanks for the articles!
Just a quick follow up question: suppose I re-phrase my original question to a more generic context like "I have 2 mice in my system, and I have widgets in my Qt such that half of the widgets should handle mouse 1 events while the other half of the widgets should handle mouse 2 events." Is there a quick way to support this usecase?
-
Two mice would not be the same situation you have with PowerMate knobs so you should rather open a new thread.
However, I don't know whether Qt receives enough information from the system to allow distinction about which cursor triggered the event.