PDA

View Full Version : Automatically scroll to current Index in QTreeView



sargeslash
28th February 2013, 14:59
I want to scroll automatically to currentIndex in verticalscrollbar of QTreeView which is populated by QFileSystemModel.
I am trying it with QPropertyAnimation on the verticalScrollBar->setValue().
I have a default index in the QTreeView which I set in a function, and so I want to scroll to it.

void MainWindow::updateTree()
{
QString dir=QFileInfo(ui->lineEdit->text()).path();
QModelIndex idx = model->index(dir);
if (idx.isValid())
{
ui->treeView->setCurrentIndex(model->index(dir));
ui->treeView->expand(idx);
}
}

I am not good with QPropertyAnimation so please help me with this.

thomas@itest
28th February 2013, 18:49
???? "QTreeView::scrollTo" is not enough ???

sargeslash
28th February 2013, 23:31
I already tried it but nothings happening

ChrisW67
28th February 2013, 23:44
So why didn't you ask, "Why isn't QTreeView::scrollTo() scrolling to display the specified index when use like this? <insert your code>"?

Two obvious options:

It is making sure the specified index is visible but you are expecting something else like automagically keeping the current index in view.
The index you have given it is not valid.

sargeslash
1st March 2013, 12:00
I am just trying to scroll down until the currentIndex is visible, I read it somewhere I need to do it with QPropertyAnimation, if u people have any better solution then plesae tell, I would be glad. Just to say I want to scroll automatically to this folder 8782