How to set the focus to a specific row/col in a TableView



  • Hello,

    I have a TableView like shown below. What I want to achieve is that if the user enters a number and presses the Enter key, the cursor is automatically placed in the next row, same column. I could catch the enter key like below, but I guess what I currently can't figure out is how to then set the focus to specific row/col.

    @ TableView {
    id: tableView
    anchors.fill: parent
    model: temperatureModel
    TableViewColumn{role: "tempAvrg"; title: "Average °C."; width: columnWidth}
    TableViewColumn{role: "tempMin"; title: "Min. °C"; width: columnWidth}
    TableViewColumn{role: "tempMax"; title: "Max. °C."; width: columnWidth}
    itemDelegate:
    TextInput {
    id: textInput
    text: styleData.value.toFixed(1)
    Keys.onReturnPressed: {
    //how can I move the focus to the next row, same column?
    console.log("Enter Pressed");
    }
    onEditingFinished: {
    temperatureModel.update(styleData.role, styleData.row, text);
    }
    }
    }
    }@


  • Lifetime Qt Champion

    Hi,

    Haven't tested it but what about the currentRow/Col properties ?

    Hope it helps


Log in to reply
 

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