Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Manage a focus property on a custom component
Forum Updated to NodeBB v4.3 + New Features

Manage a focus property on a custom component

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 468 Views 1 Watching
  • 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.
  • D Offline
    D Offline
    DavidM29
    wrote on last edited by
    #1

    Hello,

    I have a custom component that contain an Image and two button inside a rectangle.
    I created a boolean property that I want to switch from false to true once the component gain focus.
    Here is an example of the component without focus :
    0_1537252851408_56694e3c-1878-4029-8ee1-3dc5a65d1865-image.png
    and here with focus :
    0_1537252833327_7d85aec9-27ac-4b03-8417-56540f1a8e0f-image.png

    I do have multiple component like that on a page.
    What I plan here is when I press bottom arrow I give focus to the next element under it. If I press le left arrow it will press the left button of my component.
    My problem is that I don't know how could I handle the down and up arrow management to switch focus from one component to another.

    Does anybody know how can I achieve that ?

    Maybe I'm doing it all wrong and there is an easy way to achieve this kind of action. If so I'm all ears.

    Thank you in advance for your help

    J.HilkJ 1 Reply Last reply
    0
    • D DavidM29

      Hello,

      I have a custom component that contain an Image and two button inside a rectangle.
      I created a boolean property that I want to switch from false to true once the component gain focus.
      Here is an example of the component without focus :
      0_1537252851408_56694e3c-1878-4029-8ee1-3dc5a65d1865-image.png
      and here with focus :
      0_1537252833327_7d85aec9-27ac-4b03-8417-56540f1a8e0f-image.png

      I do have multiple component like that on a page.
      What I plan here is when I press bottom arrow I give focus to the next element under it. If I press le left arrow it will press the left button of my component.
      My problem is that I don't know how could I handle the down and up arrow management to switch focus from one component to another.

      Does anybody know how can I achieve that ?

      Maybe I'm doing it all wrong and there is an easy way to achieve this kind of action. If so I'm all ears.

      Thank you in advance for your help

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      hi @DavidM29

      qml has the Keys item, you can use to listen to key presses e.g

      Keys.onDownPressed: { //signal on down arrow key
                  console.log("downarrow");
                  event.accepted = true;
          }
      

      than its just a matter of keeping track on what item has focus and than call focus = true on the next one you want to have focus.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DavidM29
        wrote on last edited by
        #3

        @J.Hilk
        I agree with you that is what I imagined at first. But my problem here is to handle the focus switch from an element to another. Knowing that I can also have element that are not visible....

        I know how to get the signal from key press, but I don't know how to change my property to the right component.

        Sorry if my first question was not really clear on that.

        1 Reply Last reply
        0

        • Login

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