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. Bug in TableView: keyboard (down arrow) after selection.select() is wrong

Bug in TableView: keyboard (down arrow) after selection.select() is wrong

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 1.1k 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.
  • C Offline
    C Offline
    cscooper
    wrote on last edited by
    #1

    In my simple test code (below), everything starts out fine, the table appears and shows Fred, George, and Harold, and Fred is selected. However, if I press the down key, the "onSelectionChanged" is triggered, but Fred (row 0) is still selected. The second time I press the down key, and forever after that, the down key works as expected. Why doesn't the 'down' key work that first time?

    Thanks,
    Chris

    @ListModel
    {
    id: patientNames
    ListElement{ name: "Fred" }
    ListElement{ name: "George" }
    ListElement{ name: "Harold" }
    }

    TableView
    {
    id: patientNameTable

    anchors.top: parent.top
    anchors.bottom: parent.bottom
    anchors.left: parent.left
    width: parent.width * .25 -5
    
    Component.onCompleted:
    {
        console.log("patientNameTable.onCompleted()");
        selection.select(0);
    }
    
    model: patientNames
    
    Connections
    {
        target: patientNameTable.selection
        onSelectionChanged:
        {
            console.log("patientNameTable.selection.onSelectionChanged()");
            patientNameTable.selection.forEach(function(rowIndex) { console.log("   Row", rowIndex, "is selected")} )
        }
    }
    
    TableViewColumn
    {
        role: "name"
        title: "Name"
        width: 300;
    }
    

    }
    @

    @
    qml: patientNameTable.onCompleted()
    qml: patientNameTable.selection.onSelectionChanged()
    qml: Row 0 is selected
    qml: patientNameTable.selection.onSelectionChanged()
    qml: Row 0 is selected
    qml: patientNameTable.selection.onSelectionChanged()
    qml: Row 1 is selected
    @

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cscooper
      wrote on last edited by
      #2

      I discovered the problem, the keyboard is responding to the "currentRow" which is not the same as the selected row. The solution is that when I call selection.select(0) I also have to set currentRow=0

      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