QAbstractListModel containing a QAbstractListModel for ComboBox QML
-
Hi guys,
I have a
QAbstractListModel(let's call itVideoOptions) which is used by aListViewin 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 aComboBoxin QML.Because of this restriction it seems I can't create a
Q_INVOKABLEfunction inVideoOptionsto get the correctQAbstractListModelto 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 ListModelfrom theVideoOptions ListModeland creating the exact amount ofFormat ListModelsI need and referencing them by unique names e.gformatListModel1, formatListModel2in QML.Another possibility would be to create the
Format ListModel's and share them with theVideoOptions Elementby astd::shared_ptrand then create aQ_INVOCABLEfunction inVideoOptions 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. -
Hi guys,
I have a
QAbstractListModel(let's call itVideoOptions) which is used by aListViewin 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 aComboBoxin QML.Because of this restriction it seems I can't create a
Q_INVOKABLEfunction inVideoOptionsto get the correctQAbstractListModelto 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 ListModelfrom theVideoOptions ListModeland creating the exact amount ofFormat ListModelsI need and referencing them by unique names e.gformatListModel1, formatListModel2in QML.Another possibility would be to create the
Format ListModel's and share them with theVideoOptions Elementby astd::shared_ptrand then create aQ_INVOCABLEfunction inVideoOptions 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.@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
QAbstractListModelwhich consists of VideoOptions which each consist of aQAbstractListModelfor Format.Your proposed solution would be the one I described, as in "I defined a custom model for each
VideoOptionwhich I then plug into QML viaformatModel1,formatModel2andformatModel3.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 aQAbstractListModelbut 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.