Solved qtreeview weird behavior on column click
-
i have an object of
QTreeView
subclass, and it has 2 columns. when the first column is fully visible and the second one is partially visible, when i click on an item in second column, the view scrolls horizontally (i just to show the whole second column). how can i disable this?
and if i can't disable it, how can i make the second column fixed width? so when the view is widened, only the first column is widened and the second one just stays the same width. -
Hi,
You can modify the resizing behaviour of a column using QHeadView::setSectionResizeMode
-
@SGaist
i know about that. when i set it, the column definitely has a fixed size. the problem is that when i resize the view, the second column doesn't resize but a space is added after it (something like a third column). but that's not what i want. i need the first column widened when the view is widened, and the second column to stay fixed width (the second column should always touch right side of the view, with section resize option the newly added space doesn't let that happen)also, i don't know how to set the actual width i want it to be.
-
Then why not set
QHeaderView::Stretch
on the first column ? -
- also, i don't know how to set the actual width i want it to be.
You mean ?
http://doc.qt.io/qt-5/qheaderview.html#resizeSection
- also, i don't know how to set the actual width i want it to be.
-
@SGaist
that didn't work because column 0 didn't exist yet when i set the resize mode.
EDIT: i also needed to setQHeaderView::Fixed
for the second column, and it worked.@mrjj
that had no effect on column width.
EDIT:setDefaultSectionSize()
seemed to do the trick.reference answer used: https://stackoverflow.com/questions/47769122/qtreeview-with-fixed-column-widths
-
This post is deleted!