Unsolved QAbstractListModel containing a QAbstractListModel for ComboBox QML
-
Hi guys,
I have a
QAbstractListModel
(let's call itVideoOptions
) which is used by aListView
in QML. Now I want to create a drop down list (let's call itFormat
) for each element (video) in the VideoOptions model, which seems to be aComboBox
in QML.Because of this restriction it seems I can't create a
Q_INVOKABLE
function inVideoOptions
to get the correctQAbstractListModel
to use in aComboBox
.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 ListModel
from theVideoOptions ListModel
and creating the exact amount ofFormat ListModels
I need and referencing them by unique names e.gformatListModel1, formatListModel2
in QML.Another possibility would be to create the
Format ListModel
's and share them with theVideoOptions Element
by astd::shared_ptr
and then create aQ_INVOCABLE
function inVideoOptions ListModel
to 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
VideoOptions
instantiated at one single place. -
@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. -
I think I understood your answer, but this does not allow me to create a
QAbstractListModel
which consists of VideoOptions which each consist of aQAbstractListModel
for Format.Your proposed solution would be the one I described, as in "I defined a custom model for each
VideoOption
which I then plug into QML viaformatModel1
,formatModel2
andformatModel3
.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
QAbstractListModel
and not have them independent of each other.Or maybe is there another way to create a drop-down
ComboBox
list without using aQAbstractListModel
but 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.