PDA

View Full Version : QTreeWidget won't scroll horizontally



JimDaniel
8th January 2008, 21:39
Hi, this has really been bugging me.

I have a QTreeWidget in a QVBoxLayout and that layout is set to a QGroupBox. For whatever reason, the treeview doesn't recognize when it needs to scroll horizontally, and if I manually call setHorizontalScrollPolicy(Qt::ScrollBarAlwaysOn); the scroll bar is visible, but there is no bar to scroll. The strangest part is that the vertical scroll works just fine.

Here is some of my code...I didn't put the code where I populate the treeview as its long and to my mind irrelevant.



treeWidget = new QTreeWidget();
treeWidget->setColumnCount(1);

verticalLayout = new QVBoxLayout();
verticalLayout->addWidget(treeWidget);

groupBox->setLayout(verticalLayout);


I've tried populating the treeview both before its set to the layout and after. No change.

Does anyone have any ideas? Seems like it should work...

jpn
9th January 2008, 20:41
You would have to turn the stretching off:

treeWidget->header()->setStretchLastSection(false);
Notice that QHeaderView provides several methods for handling section resizing.

JimDaniel
10th January 2008, 15:42
Thanks alot. I didn't see your post and finally got it to work by calling treeWidget->resizeColumnToContents(0) each time a node was expanded. Your method seems much cleaner.

pravin.chaudhary
23rd January 2008, 08:53
Thanks, even I was facing this problem.

in addition, I had to write following line


header()->setResizeMode(QHeaderView::ResizeToContents);