Multiple inheritance from QOBject. New Issue related
-
Hello everyone.
I read a bit on this topic before posting this. It looks that multiple inheritance from QObject is forbidden unless the inheritance is set as private in all subclasses but one.
In my project, I use Qt Model/View in Qt 5.14.2 and I have a Model class inheriting from QAbstractListModel. I want to allow selection in my model and I found this useful QItemSelectionModel class I could inherit from, taking advantages of all the features already in place for selection of items in the model. Here it comes the problem, I can't inherit from both QAbstractItemModel and QItemSelectionModel at the same time. I know I can instantiate a QItemSelection object in my model and use that to manage selection but It would be good if QItemSelectionModel worked as an interface to inherit from rendering a model "Selectable".
-
Selection is something done on view, not on model. The model should not know whether items are selected or not.
If in your case model needs to be notified about selection (it's saved to database etc.), you can (ab)use Qt::CheckStateRole property and simply set certain items checked when they are selected.