PDA

View Full Version : QTreeView autoresize and autoexpand



scrasun
26th September 2009, 15:31
Hello,

In a program that I am making, there is a qtreeview used to show a directory tree, I have a few questions about the widget.

1) Can I make the tree automatically expand to show a specific path (eg where the file currently in use is)?

2) When more folders are opened in the view, the column does not expand to accommodate them (and no scroll bar appears), so the contents of folders lower in the tree are not visible unless you manually resize the column width. Is there anyway to make the column 'auto-resize' to accommodate more items?

Thanks in advance.

Scrasun

wysota
26th September 2009, 16:18
1) Can I make the tree automatically expand to show a specific path (eg where the file currently in use is)?
void expandToIndex(QTreeView *tv, QModelIndex index){
while(index.isValid()){
tv->expand(index);
index = index.parent();
}
}[/code]


2) When more folders are opened in the view, the column does not expand to accommodate them (and no scroll bar appears), so the contents of folders lower in the tree are not visible unless you manually resize the column width. Is there anyway to make the column 'auto-resize' to accommodate more items?

I'm not sure I understand the question but maybe QTreeView::resizeColumnToContents() helps you.