⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

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:
    model: modelYouUse
    delegate: Item{
    //do that you want to each element controlling by index

    I hope it is usefull for you.

  • 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).


Log in to reply