[Qt-interest] QTreeView::scrollTo at application start

Luis Garrido luisgarrido at users.sourceforge.net
Thu Aug 13 13:10:25 CEST 2009


Thanks for your insightful answer, Stephen!

> I'm guessing the currentPathIndex is not valid. FSM is populated dynamically
> AFAIK, which means that the row you want to scroll to is not in the model
> yet when the application starts.

That's a good guess that set me on the right track, but it is a bit
more difficult.

The problem is the asynchronous way the model rows are filled. First
of all, scrollTo goes straight to the target, adding the intermediate
folders. For instance, if I try to index("/var/tmp/kompoza/music/gig")
this is the sequence of rowsInserted signals:

Rows inserted: / [0-0]
/var
Rows inserted: /var [0-0]
/var/tmp
Rows inserted: /var/tmp [0-0]
/var/tmp/kompoza
Rows inserted: /var/tmp/kompoza [0-0]
/var/tmp/kompoza/music
Rows inserted: /var/tmp/kompoza/music [0-0]
/var/tmp/kompoza/music/gig

That's when index() returns.

And then it begins to fill the rest of "/" subdirectories, most likely
to cache the first tree expansion:

Rows inserted: / [1-19]
/selinux
/usr
/boot
/mnt
...<snip>

When I issue the scrollTo command it begins to fill the gaps of the
intermediate subdirectories to expand them:

Rows inserted: /var [1-17]
Rows inserted: /var/tmp [1-13]
Rows inserted: /var/tmp/kompoza [1-1]
Rows inserted: /var/tmp/kompoza/music [1-1]

I'd say in this respect scrollTo doesn't work as intended for
asynchronous models, so it shouldn't be considered reliable.

It is difficult to envision a workaround for this, unless we assume
that FSM only issues rowsInserted signals after a subdirectory has
been _completely_ populated. In this case we could expand
progressively the tree from the root on, monitoring the rowsInserted
signals until we get one whose parent is the parent of our target
directory. Then we can disconnect from the signal and use scrollTo.

But if FSM implementation allows for partial populations for long
subdirectories the only way to reliably determine when the population
has finished is to keep a separate list of the parent directory
entries and "tick" them as they are inserted in the model.

I'd suggest for next versions of FSM that this issue is addressed by a
specific signal (all asynchronous stuff should have a way to signal it
has finished, otherwise it is very difficult to automate).

A quick ugly hack is to issue two scrollTo commands separated by a
reasonable amount of time.

As things stand now I don' t think it is worth the pain, I'll use
QDirModel instead.

Cheers,

Luis



More information about the Qt-interest-old mailing list