QML Dynamic Focus



  • Hi, I'm working in an application running under an embedded linux device. It
    is a complex application that has many QML components which are created and
    destroyed when necessary. The user interface is the touchscreen and 4 buttons
    accessible through standard GPIO's. What I need to achieve is to change focus
    "dynamically" between all the present components, without having to
    modify every qml document (if it is possible), when a button is pressed. Each
    button has a dedicated signal that the root qml component (ApplicationWindow)
    receives. I'm aware of the FocusScope implementation but I wanted to know if
    there is some mechanism to access all the root's children and their
    properties. Thanks in advanced. Best regards


  • Moderators

    Hi @geageagea,

    What I need to achieve is to change focus
    "dynamically" between all the present components, without having to
    modify every qml document (if it is possible), when a button is pressed.

    Yes you can set focus property of those component to true when required.

    ... but I wanted to know if
    there is some mechanism to access all the root's children and their
    properties.

    One way to access children properties is to create an alias in parent and which is binded to the individual children.

    May be I have not completely understood your question. Can you narrow it down and provide a sample code or some sort of representation of what you are trying to achieve ?



  • Hi @p3c0,
    Thanks for your response. Sorry if I can't make myself clear but English is not my native language. My application has many QML components and recently I've been requested to implement these function keys (simple buttons attached to GPIOs) as navigation keys. There are 3 keys: up, down and enter. Pressing up or down should highlight the next or the previous element on the screen and pressing enter should simulate the click. So I was wandering if it is possible to access to every child recursively through a simple function. I can't figure it out how would I do it but that would be the idea. Doing this, I want to avoid modifying every single element in the project.


  • Moderators

    @geageagea

    So I was wandering if it is possible to access to every child recursively through a simple function.

    Use children property to iterate over all children of parent Item.
    Eg.

    for(var i=0; i<root.children.length; i++)
         console.log(children[i])
    


  • Hi @p3c0
    Sorry for keeping you waiting (?) but I was working on another things. I have tried what you said but the element ApplicationWIndow has no property children. On console, whenever I access to root.children.length (root is the id of my ApplicationWIndow) it says

    "TypeError: Cannot read property 'length' of undefined"
    

    So, I keep looking and I found out that instead of the children property I have to use the contentItem property and it works.
    Thanks a lot for the help
    Best regards
    Gustavo


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.