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. Problem with DoubleSpinBox in TableView
Qt 6.11 is out! See what's new in the release blog

Problem with DoubleSpinBox in TableView

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmltableviewdoublespinbox
1 Posts 1 Posters 109 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.
  • F Offline
    F Offline
    fantaz
    wrote last edited by fantaz
    #1

    Hi,
    I'm using Qt 6.11.1, and wanted to use DoubleSpinBox as a table view edit delegate. The values are changed if I use spins.
    However, if I manually change the number, say from 4 to 10, and hit enter, or tab, then nothing happens.
    Interestingly, in onCommit slot, the contentItem.text displays the value I had put in the spin box, while the value is not modified.
    The code in question is shown below.
    Am I doing something wrong or there is a bug?
    best regards,
    fantaz

    import QtQuick
    import QtQuick.Controls
    import Qt.labs.qmlmodels
    
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("TableView with DoubleSpinBox")
    
        TableModel {
            id: myTableModel
            TableModelColumn { display: "pt_x" }
            TableModelColumn { display: "pt_y" }
            rows: [
                { pt_x: 0., pt_y: 0. },
                { pt_x: 1., pt_y: 8. },
                { pt_x: 2., pt_y: 4. },
                { pt_x: 3., pt_y: 6. }
            ]
        }
    
        TableView {
            anchors.fill: parent
            model: myTableModel
            delegate: TableViewDelegate {
                id: tableCell
                clip: true
                implicitWidth: 100
                background: Rectangle{anchors.fill: parent; border.color: "darkgray"}
                contentItem: Text {
                    text: model.display
                    font.pixelSize: 16
                }
                TableView.editDelegate: DoubleSpinBox {
                    width: parent.width; height: parent.height
                    anchors.centerIn: parent
                    value: display
                    from: -10; to: 30
                    stepSize: 1
                    editable: true
                    TableView.onCommit: {
                        console.log(`onCommit: content: ${contentItem.text}, value: ${value}`)
                        model.display = value
                    }
                    onValueChanged: {
                        console.log(`onValueChanged: content: ${contentItem.text}, value: ${value}`)
                    }
                    onValueModified: {
                        console.log(`onValueModified: content: ${contentItem.text}, value: ${value}`)
                    }
                }
            }
        }
    }
    
    
    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