Unsolved Minimum Size For qtreewidget columns
-
Re: Minimum size for QTableWidget collums/multiple resize modes?
Facing similar issue as the above mentioned topic. But need help with just setting the minimum/default width to the column so that when table is created the column size should be fixed and when user tries to reduce size of column it cannot be reduced beyond the fixed size. I couldn't find any solutions for this. Any idea how this can be resolved.
-
Hi,
Looks like you want to fix the sections size in the horizontal QHeaderView for your QTreeWidget.
-
@SGaist Hi
I just want to change the minimum width of only one section in the header. I don't see a direct method in header class. I want something similar to setMinimumSectionSize(int) but it needs to take 2 arguments (Index, Width) so that it will set the minimum width to the given index. Is there a way to do this? -
@Abhi_Varma
I don't think there is a call for a minimum section size for just one column/row.There are several ways to achieve what you want. But I think in the case of a
QTreeWidget
(as opposed to aQTreeView
) the most obviously-supported way would be QTreeWidget::setHeaderItem(QTreeWidgetItem *item) and in theitem
QTreeWidgetItem::setSizeHint(int column, const QSize &size). You would have to try. There may be better/simpler ways, but that's my first thought. -
@JonB This was not working. When we setMinimumWidth it restricts the user from reducing the size of column beyond that width. I want to restrict user from reducing the size of 1 column beyond the custom set minimum width of that column. Your solution was not restricting me from reducing the size of column.
For Example, Say I have 3 Columns. I setMinimumWidth(20) for all the sections of header, For my first column it should have a width of 80 and restrict user from reducing size of column but allow increasing column size.
I understand there are no direct ways to achieve this but any workaround will help.
-
@JonB , @SGaist I found a bad hack, I know for sure this is not the correct way to program this feature but what I have done is whenever we resize a column a SIGNAL( sectionResized(index, oldSize, newSize) ) is emitted by header view class. I connected a SLOT (OnSectionResized(index, oldSize, newSize) )
void OnSectionResized(int index, int oldSize, int newSize) { Q_UNUSED(oldSize); if( index == FIRST_COLUMN_INDEX && newSize < FIRST_COLUMN_MIN_WIDTH ) { pTreeView->setColumnWidth(index, FIRST_COLUMN_MIN_WIDTH ); } }
Any other workaround is much appreciated.