V
V
Vitaly Petrov2016-02-08 17:36:37
Qt
Vitaly Petrov, 2016-02-08 17:36:37

QML StackView + ListView: accessing specific model element?

I want to build navigation in the application completely on a StackView, in which I have two pages: a list with a ListView working with a C ++ model inherited from QAbstractListModel and a page with detailed information. In general, more or less standard navigation for a mobile application.
But I ran into a problem - how to correctly use the model on the details page? It seems to be easy to forward the model itself and the current index inside, but then you have to fence the garden to get data through additional. functions, and this data will then not be automatically updated after dataChanged.
It is assumed that such a problem should be solved inside a delegate that has two states like list and detail, but I need a StackView.
What I have tried:
- changed the parent of the delegate, but I need normal animations and this approach is not compatible with them. In addition, after returning, the delegate does not get up exactly in the previous coordinates, these are Flickable features and there is nothing to be done about it.
- did the filter model based on the existing one with 1 element and listview. I don't like it at all because it's a crutch.
- received data referring to the model - garbage comes out as I wrote above.
I can't think of a better solution with my brain. I also thought about copying the delegate in memory, but have not tried it yet. I am also thinking about writing a qml plugin, but I have not yet taken it in the hope of finding a ready-made solution.
Ideally, I would like to find something like a standalone delegate or DetailsView to which it is enough to give the model and index, and then access the data as in a regular delegate.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Petrov, 2016-02-08
@vitaly_KF

In general, I settled on the version with QSortFilterModel. I overridden the filterAcceptsRow method, where I filter everything so that 1 element remains.
Then I created a new component, inside of which there is a ListView with interactive = false and I put a delegate and a filtered model in it. According to tests, it works stably and quickly for 1000+ records.
PS: I corrected the errors in my question, I wrote from the phone in a traffic jam, please forgive those who had to see this before editing =)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question