I have a Flickable
that includes a large number of TextField
objects laid out in a column with each TextField anchored to the bottom on the previous TextField. Everything is working fine except that when I use the tab key to navigate through these fields, eventually the focus goes to a TextField that is outside the visible rectangle of the Flickable
and then the user can't see the cursor until they scroll down the Flickable manually.
Essentially I'm looking for some kind of ".ensureVisible()" method such that when a TextField receives the focus, the Flickable is automatically scrolled so that the just-focused TextField is entirely visible.
Have you considered a more model-ar approach to this? I mean if you use something like a
ListView
you can simply change thecurrentItem
at which point the view will automatically scroll to it if it is out of the visible range.Additionally, it will only load the text elements that are in the visible range, saving on some memory.
But even with your current approach it won't be that complex to ensure visibility.
The solution is quick and cruddy, but it will be trivial to put it into production shape. It is important to map to the
contentItem
rather than the flickable, as the latter would give the wrong results, taking the amount of current scrolling into account. Using mapping will make the solution agnostic to whatever positioning scheme you might be using, and will also support arbitrary levels of nested objects.