Skip to content
QtWS25 Last Chance
  • QColumnView in Qml

    Unsolved QML and Qt Quick qcolumnview
    1
    0 Votes
    1 Posts
    232 Views
    No one has replied
  • 0 Votes
    2 Posts
    982 Views
    Guy GizmoG
    Someone on stackoverflow was kind enough to point out my error. My parent method() should have been: QModelIndex MyModel::parent(const QModelIndex &index) const { if (!index.isValid()) { return QModelIndex(); } QObject *item = (QObject *)index.internalPointer(); Directory *parentItem = qobject_cast<Directory *>(item->parent()); if (!parentItem || parentItem == invisibleTopLevelDirectory()) { return QModelIndex(); } Directory *parentOfParentItem = qobject_cast<Directory *>(parentItem->parent()); if (!parentOfParentItem) { return QModelIndex(); } int listIndex = parentOfParentItem->indexOfItem(parentItem); if (listIndex < 0) { return QModelIndex(); } else { return createIndex(listIndex, index.column(), parentItem); } }
  • 0 Votes
    3 Posts
    2k Views
    J
    @Chris-Kawa Hi, Thank you for the prompt reply. The bug was in my model as you said, but I think I've found the problem. It turns out I needed the following: if(!hasIndex(row, column, parent)) return QModelIndex(); In my "QAbstractItemModel::index()" function. I didn't think the view widget would call "index()" with out of bound row/column combinations since it can use "QAbstractItemModel::rowCount()" and QAbstractItemModel::columnCount()" to get the structure of the model. Thanks again for your help.