Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTreeView->setRowHidden() does not work

QTreeView->setRowHidden() does not work

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 4.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lvignals
    wrote on last edited by
    #1

    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 :-)

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goblincoding
      wrote on last edited by
      #2

      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?

      http://www.goblincoding.com

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved