I
I
Inquisitor2013-01-09 10:32:13
Qt
Inquisitor, 2013-01-09 10:32:13

Scroll bar inside a separate QTreeView column

Qt 4.8.0.
There is a QTreeView with one column, the header is hidden and should not be shown.
Inside is a hierarchical tree of elements of arbitrary nesting.
Elements are named and sooner or later they won't fit into the column in width.
The resize can work for the entire QTreeView if the column width matches the content width (as if the title was displayed and the user double-clicked).

Tried to do so:
еreeView->header()->setResizeMode(QHeaderView::ResizeToContents)
There is no effect.
I tried to call this method on the events of clicking on an item or changing the selected item.
There is no effect.

How to make a column automatically change width? The view itself should not change its width.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Inquisitor, 2013-01-09
@Inquisitor

I solved it by hooking on the collapsed and expanded signals, and called resizeColumnToContents() in the handler.

I
Inquisitor, 2013-01-09
@Inquisitor

Remade.
After setModel , you need to set the following for the header() of the view:
setResizeMode(relevantColumn, QHeaderView::ResizeToContents)
setStretchLastSection(false)
The first time I set only resize mode. That's where the mistake was.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question