开发者

How to register all selected entries from a QListView inside a wizardpage?

I've got a QListView inside a wizardpage. There are several entries and multiple selection is acti开发者_StackOverflowve. 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜