There is no natural size for a tree view. A QTreeView is a QAbstractScrollArea. If the content, i.e. the table cells, grow larger than the area available to display it, dictated by the containing layout, then the scroll area gains scroll bars. If you force the horizontal scroll bars to stay hidden then you will have no way to access data outside the current view port. Under no circumstance will the table view automatically resize itself; its sizeHint() is not derived from its content.
If you want a column to automatically occupy all the remaining space within the current view port then you want to set the section's resize mode QHeaderView::setResizeMode() to QHeaderView::Stretch. If you want the column to always match the content within it then set the resize mode to QHeaderView::ResizeToContents. The QTreeView::setWordWrap() function may also be of use to make longer items viewable. None of these options changes the size of the QTreeView.
If you really want to resize tree view based on its content then you will need to code to calculate the "correct" size and force it. Set all the sections to QHeaderView::ResizeToContents and query them for their size after every data update to get a reasonable starting point. No matter how much sense it makes you eventually hit the point where the content is too wide for the screen and you are back to where you started.
Bookmarks