Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QML Table View with itemdelegate and row delegate



  • Currently have the table view connected to QSqlQueryModel and fetching data.

    I use rowdelegate to create an expansion like so:

                rowDelegate: Item {
                    id: tvRowDelegate
                    height: 65
                    state: "collapsed"
                    states:
                      [
                        State {
                            name: "collapsed"
                            PropertyChanges { target: tvRowDelegate; height: 65; }
                        },
                        State {
                            name: "expanded"
                            PropertyChanges { target: tvRowDelegate; height: 100; }
                         }
                      ]
                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            tvRowDelegate.state = (tvRowDelegate.state === "collapsed") ? "expanded" : "collapsed";
                        }
                    }
                }
    

    And I want to combined two columns of text for when I "drop down" or expand the row:

                itemDelegate:  Rectangle {
                    id: eventItem
                    width: parent.width
                    height: 65
                    color: "#ECEEEE"
                    Text {
                        id: txtItm
                        height: 55
                        leftPadding: 5
                        //TODO
                        text: ((styleData.column === 0) ? formatDT(styleData.value) : ((styleData.column === 1) ? styleData.value : ((eventLogView.height === 65) ? styleData.value : sqlELmodel.combineColums(styleData.row, 2, 3))))
                        //text: ((styleData.column === 0) ? formatDT(styleData.value) : ((styleData.column === 1) ? styleData.value : styleData.value))
                        font.pixelSize: 19
                        font.family: "NotoSans"
                        horizontalAlignment: Qt.AlignLeft
                        verticalAlignment: Qt.AlignVCenter
                        elide: Qt.ElideRight
                    }
                    Rectangle {
                        width: parent.width
                        height: 10
                        color: "#FFFFFF"
                    }
                }
    

    But the item delegate does not seem to be able to access the state variable of the row delegate. Not am I able to try to sense the height of the expanded row. Thoughts on how to solve this issue?

    Thanks,
    -Rich



  • Delegates are Components which means, their ids do not reference any specific instance of the delegate. Because of this you cannot query properties or get any kind of state data by using ids or referring to the itemDelegate or rowDelegate properties.

    I would typically resolve this kind of thing by adding an expanded bool property into the model. Then set your states to switch using a "when:" clause (to avoid the string comparison logic which is slower) and you should be able to switch your SQL data based on this value as well.



  • Hmmm, let me research some more on that. If the model is a QSqlModelQuery not quite sure how to expand the model.


Log in to reply