PDA

View Full Version : QTreeWidget horizontal scrollbar not working



agqvis
17th February 2012, 16:58
I see in the following thread that there are problems with QTreeWidget and horizontal scrollbars.

http://www.qtcentre.org/threads/1239-QTreeWidget-ScrollBar

The above thread says this problem is supposed to be fixed, but I am using Qt 4.7.4 (open source version) and I see that the problem is still there.

Here is the problem:

I have a QTreeWidget in which each item has an icon and a text. The widget has been set to have horizontal and vertical scrollbars "as needed".
The vertical scrollbar appears as expected. However, the horizontal scrollbar only appears when the size of the widget has shrunk to the point where it covers the icon.
When the widget is shrunk to cover the text part, the horiz. scrollbar does not appear.

And even when the horiz. scrollbar appears, it thinks the item is as wide as the icon only and therefore scrolls very little to show the icon. The text is still not visible.

It seems to me that QTreeWidget does not have the proper size of each item. Is there a fix or a workaround for this? Any help is appreciated.

Thanks,

--abhijit

Spitfire
21st February 2012, 09:20
I don't think it's a bug.
It seems to be designed this way.
The scroll bar will apear only when view is reduced below value of headerMinimumSectionSize.
You can set headerStretchLastSection to false and alow user to adjust the width of the column, or set headerMinimumSectionSize to whatever the width of visible items is every time you expand/collapse new item.

QHeaderView (http://developer.qt.nokia.com/doc/qt-4.8/qheaderview.html) is the place to have a look at.

agqvis
12th April 2012, 23:12
Thanks, the solution you proposed works.