【发布时间】:2019-02-28 17:10:31
【问题描述】:
我正在自己创建一个完成程序,使用 ComboBox 和 QTreeView(用于提案列表)。
MyComboBox::MyComboBox( QWidget *p_parent ) : QComboBox( p_parent )
{
setEditable(true);
m_view = new QTreeView();
m_view->expandAll(); // this command does not work!!!
m_view->setItemDelegate( new CompleterDelegate(m_view));
CompleterSourceModel *m_sourceModel = new CompleterSourceModel(this);
CompleterProxyModel *m_proxyModel = new CompleterProxyModel(this);
m_proxyModel->setSourceModel(m_sourceModel);
setView(m_view);
setModel(m_proxyModel);
connect(this, &QComboBox::currentTextChanged, this, &MyComboBox::showProposalList);
}
我这里树模型的数据结构是父子关系。有了上面的构造函数,当我把我的数据放入模型中后,孩子们被隐藏了,只有父母们可以看到。
为了查看所有项目(儿童),我必须使用 m_view->expandAll() after 我将数据放入模型中。有什么办法可以在构造函数中做到这一点,所以每次我将数据放入模型(无论我的数据是什么)时,所有项目(父母和孩子)都会自动展开?
【问题讨论】: