2
votes

I have the following Table-View and the value role contains double values. How can I format the output so that it only shows a specified number of digits (or scientific notation)?

TableView {
    id: tableView
    x: 20
    y: 24
    width: 324
    height: 150
    model: myModel
    TableViewColumn {
        role: "name"
        title: "Name"
    }
    TableViewColumn {
        role: "value"
        title: "Value"
    }
}
1

1 Answers

3
votes

Use a delegate in the TableViewColumn:

TableView {
    id: tableView
    x: 20
    y: 24
    width: 324
    height: 150
    model: myModel
    TableViewColumn {
        role: "name"
        title: "Name"
    }
    TableViewColumn {
        title: "Value"
        delegate: Text {
            text: model.value.toFixed(2)
        }
    }
}