Skip to content
QtWS25 Last Chance
  • 0 Votes
    4 Posts
    115 Views
    Ok I've rewrite the test class as my own so I can debug. Here were the problems for any1 struggling with it too... int GenericTreeModelGroup::rowCount(const QModelIndex &parent) const { if (parent.column() > 0) { return 0; } VirtualNode *node = nodeFromIndex(parent); return node ? node->children.size() : 0; } Needed to add if (parent.column() > 0) { return 0; } So that I don't return row count XX for children at column 1/2/3/4/5. The second problem was with parent () QModelIndex GenericTreeModelGroup::parent(const QModelIndex &child) const { if (!child.isValid()) return QModelIndex(); VirtualNode *childNode = nodeFromIndex(child); if (!childNode) { //|| childNode == mRootNode || !childNode->parent || childNode->parent == mRootNode) return QModelIndex(); } VirtualNode *parentNode = childNode->parent; VirtualNode *grandParent = parentNode->parent; int row = grandParent ? grandParent->children.indexOf(parentNode) : mRootNode->children.indexOf(parentNode); if (row == -1) { return QModelIndex(); } // Use column 0 for the parent return createIndex(row, 0, parentNode); } If you have a row -1, it means you have "ROOT" item, which should return QModelIndex() and not -1,-1, data QModelIndex of the model. After these 2 changes, all started to work. Yay!
  • 0 Votes
    5 Posts
    2k Views
    I had misconfigured ensureVisible's margins , and the view's size and the scene's rect . Now it works fine :)
  • 0 Votes
    2 Posts
    968 Views
    For item to be editable you would implement flags() in your model and make sure the returned flag set contains Qt::ItemIsEditable. You'd also need to implement the setData() method and handle Qt::EditRole in the data() method. For the columns from the database just return the base implementation of these methods and provide override only for your extra column.