Reputation: 201
I placed QTreeWidget into QVBoxLayout.
self._tree = QTreeWidget()
layout = QVBoxLayout()
layout.addWidget(self._some_other_widget)
layout.addWidget(self._tree)
layout.addStretch()
self.setLayout(layout)
All nodes in this tree widget are always expanded. I would like to create this tree widget with minimal height (for example, for one row/item). When new items are added this tree widget also grows to show all items. How can this be done? Thank you in advance.
Upvotes: 0
Views: 225
Reputation: 201
There are at least two solutions:
Use self._tree.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents)
. Thank you for this, G.M.
I have also found another solution:
def sizeHint(self):
return self._sizeHint()
def minimumSizeHint(self):
return self._sizeHint()
def _sizeHint(self):
sh = super().sizeHint()
if self._item_count > 0:
return QSize(sh.width(), self.sizeHintForRow(0) * self._item_count)
else:
return QSize(sh.width(), 40)
Upvotes: 0