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. Focus shift across qml files without using focusscope id

Focus shift across qml files without using focusscope id

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 571 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.
  • S Offline
    S Offline
    Satyakaama
    wrote on last edited by
    #1

    Hello All,

    There is scenario, where it is required to shift focus across qml files(Components).

    mod1.qml

    import QtQuick 2.0

    Item{

    Row{
    Rectangle{
        id : rect3
        color: activeFocus ? "grey" : "green" ;
        width : 100
        height : 100
        focus: true
        KeyNavigation.right:   rect4
        KeyNavigation.left:   ib1
    
    }
    Rectangle{
        id : rect4
        color: activeFocus ? "grey" : "yellow" ;
        width : 100
        height : 100
        KeyNavigation.left: rect3
        KeyNavigation.right:    ib1
    
    }
    }
    

    }

    mod2.qml

    import QtQuick 2.0

    Item{
    anchors.bottom: parent.bottom
    Column{
    Rectangle{
    id : rect1
    color: activeFocus ? "red" : "grey";
    width : 100
    height : 100
    focus: true
    KeyNavigation.right: rect2
    KeyNavigation.left: vm1

    }
    Rectangle{
        id : rect2
        color: activeFocus ? "blue" : "grey";
        width : 100
        height : 100
    
        KeyNavigation.left:  rect1
        KeyNavigation.right: vm1
    
    }
    }
    

    }

    main.qml

    import QtQuick 2.3
    import QtQuick.Window 2.2

    Window {
    visible: true

    title: qsTr("Hello World")
    
    function focusshift()
    {
    

    //Is it possible to do focus shift between mod1 and mod2 without using focusscope id ?

    }
    Component.onCompleted: {
        focusshift();
    }
    

    }

    Thanks in advance

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Not possible without FocusScope. Qn - What is the problem are you trying to solve ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Satyakaama
        wrote on last edited by
        #3

        Problem statement :

        What is the best approach to dynamically create components and assign key navigation focus ?

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          If you are using the dynamic component KeyNavigation is complicated to achieve. You can use the FocusScope and achieve the same.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          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