void NTrashTree::calculateHeight() { int h = 0; int topLevelCount = topLevelItemCount(); for(int i = 0;i < topLevelCount;i++) { QTreeWidgetItem * item = topLevelItem(i); h += calculateHeightRec(item); h += item->sizeHint(0).height() + 5; } if(h != 0) { setMinimumHeight(h+5); setMaximumHeight(h+5); } this->setMaximumWidth(this->sizeHint().width()); }
int NTrashTree::calculateHeightRec(QTreeWidgetItem * item) { if(!item) return 0; QModelIndex index = indexFromItem(item); if(!item->isExpanded()) { return rowHeight(index); } int h = item->sizeHint(0).height() + 2 + rowHeight(index); int childCount = item->childCount(); for(int i = 0; i<childCount; i++) { h += calculateHeightRec(item->child(i)); } return h; }
void NTrashTree::calculateHeight() { int h = 0; int topLevelCount = topLevelItemCount(); for(int i = 0;i < topLevelCount;i++) { QTreeWidgetItem * item = topLevelItem(i); h += calculateHeightRec(item); h += item->sizeHint(0).height() + 5; } if(h != 0) { // h += header()->sizeHint().height(); setMinimumHeight(h); setMaximumHeight(h); } }