How to Send Rotary Encoder Signals Only to Visible QML Components?
-
Hi,
I am working on a Linux device using a Rotary Encoder with a Qt QML application. I have a custom QML component named RotaryEncoder. When an event is read from the rotary encoder file, the signal is sent to all RotaryEncoder components currently instantiated.
I tried checking the visible and enabled properties of these components, but it doesn't solve the issue. The problem is that components inside a StackView do not have their visible property set to false even when they are not displayed on the screen.
For example, in a MouseArea, only the visible components receive mouse signals. Is there a way to achieve similar behavior with the rotary encoder, such that only the currently visible component handles the rotary encoder events?
Additional Information:
The RotaryEncoder component behaves like a shared global signal receiver, making it challenging to filter events for just the active view in a StackView
Code Example;
Item {
id: recursivePage1RotaryEncoder { onWheelRight: listView.increase() } ListView { id: listView } } Item { id: recursivePage2 RotaryEncoder { onWheelRight: listView2.increase() } ListView { id: listView2 } }
In this scenario, both pages (recursivePage1 and recursivePage2) are receiving the rotary encoder signal simultaneously, causing conflicts and unexpected behaviors. Ideally, only the active page should handle the signal, but both pages are responding at the same time.
Any suggestions or best practices to limit rotary encoder signals to the visible components would be greatly appreciated.
Let me know if you'd like to refine it further!
-
What exactly are you trying to achieve ?
First thing that surprises me : listView(2).increase() : ListView doesn't have such method.
If you are attempting to scroll with mouse wheel within your ListView, you shouldn't need any RotaryEncoder or whatsoever. Only the currently active view scrolls.
ListView inherits from Flickable, and if I understand it right, what you are trying to achieve is already implemented by Flickable. -
Oh ok maybe you are dealing with an external hardware rotary encoder that is not a mouse wheel ?
Then the activeFocus (or activeFocusOnTab) property is what you may be looking for.then that would be something like
onWheelRight: if (listView.activeFocus) listView.contentX += someConstant
-
@Yaldiz said in How to Send Rotary Encoder Signals Only to Visible QML Components?:
The problem is that components inside a StackView do not have their visible property set to false even when they are not displayed on the screen.
They do.