1

我在向导页面中有一个 QListView。有多个条目,并且多项选择处于活动状态。我希望在单击“下一步”按钮时将所选项目注册为字段。

可能吗?如果如何,导致 registerfield 无法工作,connect() 会创建一个模型索引,迭代模型行在 wizardpage:initializePage() 中不起作用。

有什么建议么?

谢谢你。

4

1 回答 1

1

这可能不是最好的解决方案,但它工作得很好:

向包含 的向导页面添加一个属性,QListView并让它返回指向选择模型的指针。比如像这样:

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*);

在 ListPage 的构造函数中,您必须qRegisterMetaTyperegisterField这样调用:

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

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

现在,您可以通过调用从向导中的任何位置访问选定的项目field("listViewSelection").value<QItemSelectionModel*>()

希望这是你所期望的。

于 2010-03-07T16:24:20.430 回答