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. KeyNavigation in ListView (FocusScope)
Qt 6.11 is out! See what's new in the release blog

KeyNavigation in ListView (FocusScope)

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

    We use keyNavigation in a ListView, using a FocusScope. If one element in the ListView is set to “disabled” we expect, the active Focus to skip over the disabled element!

    For example:

    [] is activeFocus

    • is enabled: true
      - is diabled (enabled:false)
      # is focus: true

    Initial ListView: (fig. 1)

    • [Element 1]

    • Element 2
      
    • Element 3
      

    - Element 4

    • Element 5
      

    Key.down (1): (fig. 2)

    • Element 1 
      
    • [Element 2]

    • Element 3
      

    - Element 4

    • Element 5
      

    Key.down (2): (fig. 3)

    • Element 1 
      
    • Element 2
      
    • [Element 3]

    - Element 4

    • Element 5
      

    Key.down (3): (fig. 4)

    • Element 1 
      
    • Element 2
      
    • Element 3
      

    - # Element 4

    • Element 5
      

    Key.down (4): (fig. 5)

    • Element 1 
      
    • Element 2
      
    • Element 3
      

    - Element 4

    • [Element 5]

    We expected that on Key.down (fig. 3 to fig. 4) the Element 5 will get the focus and the active Focus.
    Actually that’s not happening. After that operation the ActiveFocus is lost It seems, the ActiveFocus is simply vanishing, no element seem to be focused anymore.
    If we use the tab key it works like expected, the active focus skips Element 4 and went directly the Element 5

    Example Code:
    …

    @ ListModel {
    id: demoModel
    ListElement { name: "Element 1"}
    ListElement { name: "Element 2"}
    ListElement { name: "Element 3"}
    ListElement { name: "Element 4"}
    ListElement { name: "Element 5"}
    }

    ListView {
    width: 100
    height: 250
    id: demolistView
    model: demoModel
    delegate: Rectangle {
    id: demobutton
    width: 100
    height: 50
    enabled: index === 2 ? false : true // disable element 3
    color: "orange"

      // make active Focus visible with red border
      border.width: activeFocus? 2: 0
      border.color: activeFocus? "red": "transparent"
    
      Text{
        id: demobuttonlabel
        anchors.fill: parent
        text: name
        color: enabled ? "black" : "grey" // diasbled Text is grey
        verticalAlignment: Text.AlignVCenter
        horizontalAlignment: Text.AlignHCenter
      }
    
      MouseArea {
        anchors.fill: parent
        onClicked: {
          demobutton.forceActiveFocus() //Set activeFocus on clicked element
        }
      } // MouseArea
    } // Delegate
    

    } // ListView@

    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