Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QAbstractListModel containing a QAbstractListModel for ComboBox QML
cirquit last edited by
I have a
QAbstractListModel(let's call it
VideoOptions) which is used by a
ListViewin QML. Now I want to create a drop down list (let's call it
Format) for each element (video) in the VideoOptions model, which seems to be a
Because of this restriction it seems I can't create a
VideoOptionsto get the correct
QAbstractListModelto use in a
The basic model layout is the following:
VideoOptions (ListModel) -> VideoOption 1 (Element) -> Format (ListModel) -> Format 1 (Element) -> Format 2 (Element) -> Format 3 (Element) -> VideoOption 2 (Element) -> Format (ListModel) -> Format 1 (Element) -> Format 2 (Element) -> Format 3 (Element)
What is the Qt'iest way to solve this? I currently have a very dirty solution by uncoupling the
Format ListModelfrom the
VideoOptions ListModeland creating the exact amount of
Format ListModelsI need and referencing them by unique names e.g
formatListModel1, formatListModel2in QML.
Another possibility would be to create the
Format ListModel's and share them with the
VideoOptions Elementby a
std::shared_ptrand then create a
VideoOptions ListModelto access them from QML.
In both cases I'd be dependent on an explicit index , which I'd like to avoid because it should be only dependent on the amount of
VideoOptionsinstantiated at one single place.
rrlopez last edited by
@cirquit Hi, I would create first a ListView to contain all the VideoOption items (In this case, VideoOptions ListModel). The delegate of this ListView would be another element which also has a ListView or a repeater (depending on how much functionality from the listview you need) and set its model to the Format ListModel.
This way the first ListView displays the VideoOption items, each VideoOption item will have a repeater/ListView to show the format ListModel (this element will be the Combo Item) and then, this item would show each of the format elements.
I hope I made myself clear.
cirquit last edited by
I think I understood your answer, but this does not allow me to create a
QAbstractListModelwhich consists of VideoOptions which each consist of a
Your proposed solution would be the one I described, as in "I defined a custom model for each
VideoOptionwhich I then plug into QML via
Please tell me I understood incorrectly :( Is this a new use-case or am I missing something totally obvious? I can't seem to grasp that I'm the only one who wants to group members of a model in a single
QAbstractListModeland not have them independent of each other.
Or maybe is there another way to create a drop-down
ComboBoxlist without using a
QAbstractListModelbut still be notified of changes and have the model accessable in C++?
What are the roles of your VideoOptions QALM ?
Can't you have a role returning your Format QALM?
It's also kinda hard to help you further since this really depends on your data structure and on how you store your data underneath the model.