0

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.

Dionis
  • 1

1 Answers1

0

The Qt Model & View classes only provide the ability to have an additional checkbox, by including Qt::ItemIsUserCheckable in the flags return value of QAbstractItemModel::flags(). The Qt MV classes however don't allow any custom widget like radio buttons to be used as the delegate.

One way to render a widget would be using QStyle::drawComplexControl() in your QAbstractItemModel::paint() reimplementation, but that gets difficult when you have multiple widgets like in your case, and it doesn't handle interaction.

A better way would be to use QAbstractItemView::setIndexWidget(), but see this bug report for a Qt developer talking about the performance implications.

Thomas McGuire
  • 5,308
  • 26
  • 45
  • I found out it was possible even adding a radio button, but anyway it was far more complexed and instead of making it more dynamic, I will have just a complex code :) so it is useless i guess. I think I can do it in a qTreeView, to have the question as a parent and the description as a child of the question, and a second column for a checkbox Y/N. I will have a look at the docs you recommended. Thank you @tmcguire ! – Dionis Jan 15 '15 at 08:33