Skip to content
  • 0 Votes
    4 Posts
    2k Views
    jdcordobaJ

    That's a brilliant and elegant solution!
    Thank you bro for spending your precious time with a newbie like me!

  • 0 Votes
    1 Posts
    784 Views
    No one has replied
  • 0 Votes
    4 Posts
    7k Views
    R

    @t3685
    As stated in the OP, I know I can write specific getter/setter methods into my QAbstractItemModel subclasses.
    However, if that really was the only option then QML would be effectively useless for nontrivial data-driven applications as the data models cease to be a standard interface.

    @p3c0
    Thanks, I hadn't thought of doing it that way.
    In Qt 5.4 you can do this if you set Q_INVOKABLE on QAbstractItemModel::index(int row, int column, const QModelIndex &parent) and QAbstractItemModel::data(const QModelIndex &index, int role) methods.
    I'm guessing this has been done for you in Qt 5.5.

    I have also found that in Qt 5.4 (and presumably 5.5) it's also possible to get there via a DelegateModel (often called a VisualDataModel in the documentation), as the DelegateModelGroup within that has a get(row) function that returns an Object through which you can access the data in the same way as in a QML Delegate.
    http://doc.qt.io/qt-5.4/qml-qtqml-models-delegatemodelgroup.html#get-method
    However, I haven't yet figured out when it reads the data from the underlying model.

    Thus, if the DelegateModel has only the default DelegateModelGroup:

    myDelegateModel.items.get(%row%).model.%role_name%

    In this, myDelegateModel is a DelegateModel object (which may also be used as the model in a ListView, GridView or PathView), %row% is the row number and %role_name% is the role.
    Set myDelegateModel.rootIndex to the appropriate parent QModelIndex.

    PS: $Deity the documentation is beyond awful. So many links straight back to exactly where you are masquerading as a link to what the thing is.