Hi all,

I have the following problem with QTreeView. In my application I have a hierarchy of items. I have my own SHModel which inherits QStandardItemModel and SHView which inherits QTreeView.
My application shows the information in the SHView, but has few different modes and depending on the mode I show different things in the SHView. In the first mode I show everything in the model - it means that I show all parents and all their children. In the second mode I want to show only the children of defined parent. I want to select the parent, go to the second mode and to see only its children in the SHView.
So my question is how to hide the parent and to show only its children? I tried with setRowHidden() but if I hide the parent, so automatically its children are hidden. I also tried playing with sizeHint(). I have defined my own item edit delegate and I have predefined QItemDelegate::sizeHint() method. Also I have predefined QStandardItem and I implemented SHItem::isItemVisible() to tell me if the current item has to be shown.

Qt Code:
  1. QSize SHEditDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
  2. {
  3. QSize size = QItemDelegate::sizeHint(option, index);
  4.  
  5. const SHModel * shModel = modelFromIndex(index);
  6. SHItem* item = shModel->itemFromIndex(index);
  7.  
  8. if(!item->isItemVisible())
  9. size.setHeight(-1);
  10.  
  11. return size;
  12. }
To copy to clipboard, switch view to plain text mode 

This trick seems to work but there is a performance issue here. I don't know why but Qt calls this sizeHint() method too many times. If I set the size.height = 1, not -1, the number of calls of sizeHint() drops down.

So in brief my problem is that I want to hide parent (but show its children) in QTreeView. Do you have any other ideas?

Thanks,
Plamen