tags:

views:

50

answers:

1

Hi

I've got a QListView inside a wizardpage. There are several entries and multiple selection is active. I want the selected items beeing registered as a field when the 'next' button is clicked.

Is it possible? And if how, cause registerfield can't work, connect() nedds an modelindex, iterating over the model-rows doesn't work in wizardpage:initializePage().

Any suggestions?

Thank you.

A: 

This maybe is not the nicest solution, but it works just fine:

Add a property to the wizardpage which contains the QListView and let it return the pointer to the selectionmodel. E.g. like this:

class ListPage : public QWizardPage
{
Q_OBJECT
Q_PROPERTY(QItemSelectionModel* selectionModel READ selectionModel)

public:
   ListPage(QWidget * parent = NULL);
   QItemSelectionModel * selectionModel(void)
   {
      return listView->selectionModel();
   };
private:
   QListView *listView;
};
Q_DECLARE_METATYPE(QItemSelectionModel*);

In the constructor of ListPage you then have to call qRegisterMetaType and registerField like so:

ListPage::ListPage(QWidget * parent) : QWizardPage(parent)
{
   ...
   listView = new QListView(this);
   listView->setSelectionMode(QAbstractItemView::MultiSelection);
   listView->setModel(model);

   qRegisterMetaType("QItemSelectionModel*");
   registerField("listViewSelection", this, "selectionModel");
   ...
}

Now you can access the selected items from everywhere in the wizard by calling field("listViewSelection").value<QItemSelectionModel*>().

Hope this is what you expected.

Elrohir
Thank you very much for your answer and the fine explanation + code. Less talk more code :) I'll give it a try tomorrow.
somebody
Did it work in the end?
Elrohir
Hi sorry was too deep in writing the documentation... It didn't run yet, but i'll keep on trying.
somebody
Right now the problem is to register:qRegisterMetaType("QItemSelectionModel*");error: ‘qt_metatype_id’ is not a member of ‘QMetaTypeId<const char>’Qt4.6 Qt-Creator-1.3
somebody
Do you have Q_DECLARE_METATYPE(QItemSelectionModel*) somewhere in your includes?
Elrohir