Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set column width for QTreeWidget

Is there any way to set column width for QTreeWidget from code? I want to chage default width of first column. I'm using PySide.

like image 680
xander27 Avatar asked Feb 04 '13 16:02

xander27


2 Answers

QHeaderView::resizeSection() should do the trick, in C++ it would look like this:

myTreeWidget->headerView()->resizeSection(0 /*column index*/, 100 /*width*/);
like image 51
Chris Avatar answered Sep 22 '22 13:09

Chris


For people looking for a C++ Qt solution (tested with 5.12):

// Important to call setMinimumSectionSize because resizeSection wont work if your width is less than the minimum
treeWidget->header()->setMinimumSectionSize(25);
treeWidget->header()->resizeSection(1 /*column index*/, 25 /*width*/);

// You might also need to use this if you want to limit the size of your last column:
treeWidget->header()->setStretchLastSection(false);
like image 3
RandomName Avatar answered Sep 22 '22 13:09

RandomName