ItemDelegate vs ProxyModel Subclass
-
I'm have to create a form where some questions will be taken from the db. Each question will have two radioButtons (Yes / No), a label "Explain..." and a textEdit. Firstly I created this in a QScrollArea, where for every question in the db (taken with QSqlTableModel) all the necessary widget were created and put into the layouts.
Now I think I would better do it in a QListView, where an item will be all the question = its information (question + 2 radioButtons + label + textEdit + its Layouts). I thought I could easily do it with QAbstractItemDelegate, so I created a subclass for it, but I am having some problems though. The question are not shown at all, even are its informations. Should I use a subclass of ProxyModel instead? I found a very useful checkableProxyModel! subclass which added a checkbox for every item in a model, and I thought if it was possible to add a checkBox, maybe it is possible to add all this information?
Any idea?
Comment if you need any code.
-
Hi and welcome to devnet,
If you need custom painting like it seems, then go with QStyledItemDelegate.
-
I'd advise against using the item views system for this. It seems you need complete widgets. The checkbox that is available via the CheckableProxyModel is rendered by the item view framework itself. It is not a real widget, it just uses the rendering code for one. I know, because I write the class. It doesn't do anything else than Qt models can all do by setting the right item roles and flags.
Widgets in item views are generally not a good idea. Item views are simply not designed to do that.
What you could do, is use Qt Quick for this instead. Quicks item views are designed to be able to contain everything you want, and Quick now supplies you with Quick Controls. That means that making a delegate that is just a mini-form is easy, and you can show one for every item in your model. Quick can also be embedded (again) in widget-based applications, so even if you have more widget-based code already, it may still be an option.
Otherwise: go for your scroll-view based solution.