PDA

View Full Version : QTreeView Horizontal Scrollbar issue



Dehumanizer
13th July 2011, 07:58
I've a problem with QTreeView horizontal scrollbar, it doesn't appear. I've set horizontal scrollbar policy to ScrollBarAsNeeded, but it doesn't appear if needed. Have tried to connect expanded and collapsed signals to a slot:


connect(this, SIGNAL(expanded(QModelIndex)), this, SLOT(update_scroll_area(QModelIndex)));
connect(this, SIGNAL(collapsed(QModelIndex)), this, SLOT(update_scroll_area(QModelIndex)));

The slot consists of one line of code:


void update_scroll_area(const QModelIndex& i)
{
resizeColumnToContents(i.column());
}

This makes scrollbar working, but only when I'm expanding/collapsing the tree view items.

I need to have working horizontal scrollbar "every time", from starting the application till its end. How can it be organized?

Thank you.

UPD: Have tried this code, but didn't help:


header()->setHorizontalScrollMode(QAbstractItemView::ScrollP erPixel);
header()->setResizeMode(QHeaderView::ResizeToContents);
header()->setStretchLastSection(false);

Santosh Reddy
13th July 2011, 14:38
Scroll bars appear as and when needed by default. This is default behaviour, you don't need to set anything.

I need to have working horizontal scrollbar "every time", from starting the application till its end. How can it be organized?
Do you mean that, scroll bar should be visible even when table widget fits the veiw port? (I mean even when not needed)

Dehumanizer
14th July 2011, 06:29
I understand the 'appearance' of the scroll-bar. I don't need scrollbar to appear when it doesn't need, but when tree's content's length is larger than 'holder area', the scrollbar doesn't appear, even if I set ScrollbarAlwaysOn.

At the end of the row appears "...", instead of showing scrollbar to allow me to scroll to row's real end.
(Hope, have described my problem correctly). Can you give some advice?

Santosh Reddy
14th July 2011, 07:09
look like the column's header's text's width is considered to show/hide horizontal scroll bar, if the column's header's text's width is less than the columns's text's width the ... is appears.

I am also working on finding a solution for this, I am creating a sub-class of QTreeView and altering some veiwport size options. I am still exploring this, will post updates on this soon.

Dehumanizer
14th July 2011, 07:23
Ok, thanks for reply. Waiting for updates:)

Santosh Reddy
15th July 2011, 07:37
this should fix your problem

header()->setStretchLastSection(true);

Dehumanizer
18th July 2011, 10:41
Have tried, doesn't fix. Have you other suggestions?