C++ QAbstractListModel delegate dependency issue
-
I have yet to find a solution for this question or maybe I'm not thinking about it correctly. So I have a QAbractListModel that has two sliders (settings). I have reimplemented setData, data etc. However, the one slider value is dependent on another. If the first slider is set to false it should automatically make the second slider false and also disable it (user can't interact).
Where should this check be made, in setData()? I also have the issue of the slider value not getting actually written until the user clicks a save button. If the user navigates to another page, it should reset to the previous value. So, I guess it's technically a tempValue that is changing the slider? I'm just not sure if there is a built-in method for handling delegates that affect other delegates in a model. Any help or suggestions is greatly appreciated!
-
Does the second slider need to be set to false AND disabled, or is disabled alone sufficient?
I've typically represented this sort of relationship in the delegate, presuming that the view can be depended on for consistency.
ListModel { model: theModel delegate: Row { Switch { id: s1; checked: model.s1 } Switch { id: s2; checked: model.s2; enabled: s1.checked } Button { text: "Commit"; onClicked: { model.s1 = s1.checked; model.s2 = s2.checked; } } } }
For a solution like the above, be aware that the view can destroy delegate instances as they scroll off the screen. That can be prevented through various mechanisms such as disabling scrolling when modified, or storing the values in a temporary model.
-
@jeremy_k needs to be set false AND disabled. I am actually storing these values in a qsettings file when save is pressed and use a c++ abstractListModel (there's several different setting pages with more complex setting objects, this one just has two sliders).