Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to Send Rotary Encoder Signals Only to Visible QML Components?
Forum Update on Monday, May 27th 2025

How to Send Rotary Encoder Signals Only to Visible QML Components?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 3 Posters 277 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yaldiz
    wrote on 29 Sept 2024, 10:14 last edited by
    #1

    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: recursivePage1

        RotaryEncoder {
            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!

    G 1 Reply Last reply 29 Sept 2024, 23:11
    0
    • A Offline
      A Offline
      ankou29666
      wrote on 29 Sept 2024, 10:48 last edited by ankou29666
      #2

      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.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ankou29666
        wrote on 29 Sept 2024, 11:02 last edited by
        #3

        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
        
        1 Reply Last reply
        0
        • Y Yaldiz
          29 Sept 2024, 10:14

          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: recursivePage1

              RotaryEncoder {
                  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!

          G Offline
          G Offline
          GrecKo
          Qt Champions 2018
          wrote on 29 Sept 2024, 23:11 last edited by
          #4

          @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.

          1 Reply Last reply
          0

          4/4

          29 Sept 2024, 23:11

          • Login

          • Login or register to search.
          4 out of 4
          • First post
            4/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved