[SOLVED] How to access styleData.value



  • I defined the following TableView delegate:
    @
    itemDelegate:
    Rectangle {
    color: "#F2F2F2"
    border.color: "#cecece"
    height: 48
    Text {
    text: styleData.value
    }
    Component.onCompleted: console.log("Object item: styleData.value", styleData.value)
    }@

    The table is displaying the expected value. But console.log does not print it. What do I wrong here?



  • Hmm, correct me if i'm wrong but i think the onComplete need to be inside of text. Your Rectangle is complete but not your text. Like so:

    @
    itemDelegate:
    Rectangle {
    color: "#F2F2F2"
    border.color: "#cecece"
    height: 48
    Text {
    text: styleData.value
    Component.onCompleted: console.log("Object item: styleData.value", styleData.value)
    }
    }
    @


  • Moderators

    Hi,

    From the "Doc":http://qt-project.org/doc/qt-5/qml-qtquick-controls-tableview.html#itemDelegate-prop

    bq. Note: For performance reasons, created delegates can be recycled across multiple table rows. This implies that when you make use of implicit properties such as styledata.row or model, these values can change also after the delegate has been constructed. In practice this means you should not assume that content is fixed when Component.onCompleted happens, but instead rely on bindings to such properties.

    So the content might not be available as soon as the component gets completed and hence rely on the binding so that when the data gets available it gets reflected.


Log in to reply
 

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