QTreeView->setRowHidden() does not work



  • Hi!
    Despite trying many combinations to call setRowHidden() that method always fail silently without any kind of error.
    After banging my head against this for hours I took a look at the implementation file qtreeview.cpp and realized that there are two checks at the beginning of this method:

    @if (!d->model) return;@

    and

    @if (!index.isValid()) return;@

    Unfortunately there is no easy way for me to know under which condition (if any) I fall in?

    Below is my call to that function and also the body of QTreeView::setRowHidden().

    my method call:

    @
    standardItem->setBackground(QColor::fromRgb(210,210,210)); //this line works just fine so I know standardItem is my item
    ui->treeView->setRowHidden(standardItem->index().row(), standardItem->parent()->index(), true); //this does nothing???
    @

    Body of setRowHidden():

    @
    void QTreeView::setRowHidden(int row, const QModelIndex &parent, bool hide)
    {
    Q_D(QTreeView);
    if (!d->model) return;
    QModelIndex index = d->model->index(row, 0, parent);
    if (!index.isValid()) return;
    if (hide) {
    d->hiddenIndexes.insert(index);
    } else if(d->isPersistent(index)) { //if the index is not persistent, it cannot be in the set
    d->hiddenIndexes.remove(index);
    }
    d->doDelayedItemsLayout();
    }
    @

    Requirement is I need to dynamically hide/show some of the rows while maintaining the structure of the underlying Model attached to the QTreeView.

    Any help in figuring that out would be much appreciated.
    Thanks :-)



  • Where do you set the model on the treeview? Are you sure that model is valid by the time you want to set the row as hidden?


Log in to reply
 

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