• I have a basic appilcation of QtreeView which I am using my own class custom model to populate the data

    Now we in what sequence the following methods are called

    //! [0]
    class TreeModel1 : public QAbstractItemModel

    TreeModel1(const QString &data, QObject *parent = 0);

    QVariant data(const QModelIndex &index, int role) const;
    Qt::ItemFlags flags(const QModelIndex &index) const;
    QVariant headerData(int section, Qt::Orientation orientation,
                        int role = Qt::DisplayRole) const;
    QModelIndex index(int row, int column,
                      const QModelIndex &parent = QModelIndex()) const;
    QModelIndex parent(const QModelIndex &index) const;
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    int columnCount(const QModelIndex &parent = QModelIndex()) const;

    void setupModelData(const QStringList &lines, TreeItem1 *parent);

    TreeItem1 *rootItem;


    1. For each node : the sequence is


    followed by the

    1. header which is called every-time the treeview needs the repainting (mouse moves)

    2. the parent is called if the node is a child

    3. flags

    4. data

    Why would you care about this ?

  • Moderators

    Don't depend on any sort of order of these method calls. It's up to the view/delegate/anyone to call them in any order they want/need. Any logic that depends on any kind of order will fail at some point when you switch view, delegate, Qt version or someone calls one of these directly on your model.
    A good behaved model should return correct data from these methods no matter the order they are called in.

Log in to reply

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