Accessing QAbstractItemModel data / roles outside ListView delegate



  • A ListView delegate can easily access the data of the current item in a model that is a QAbstractItemModel subclass using the role name.
    But is it possible to access model data outside the delegate (without making it explicitly available as properties of the delegate)?



  • Hi,
    The way that I thought was:
    @
    Repeater{
    id:repeterIterator
    model: modelYouUse
    delegate: Item{
    Component.onCompleted:{
    //do that you want to each element controlling by index
    }
    }
    }
    @

    I hope it is usefull for you.
    Best,
    Fernando.



  • Hi,

    There isn't any built-in way to access the data -- the typical workaround is to add slots (or Q_INVOKABLEs) to your model that can be called from QML to access this data. If you are only interested in the data from a single delegate, you could also consider "pushing" that information to a property higher up in the context chain (e.g. push the value to a property of the ListView when the delegate is clicked on).

    Regards,
    Michael


Log in to reply
 

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