k06*_*06a 2 c++ model-view-controller qt qtreewidget qtreeview
我正在使用QStandardItemModel和QStandardItem.
我不想写自己的模型和任何代表.
我只想在第二栏中找到QComboBox'的复选框树...
m_model->setColumnCount(2);
for (int i = 0; i < sectionCount; i++)
{
QStandardItem * section = new QStandardItem(tr("Section %1").arg(i+1));
section->setCheckable(true);
section->setCheckState(Qt::Checked);
for (int j = 0; j < itemsCount; j++)
{
QStandardItem * item = new QStandardItem(tr("Item %1").arg(j+1));
item->setCheckable(true);
item->setCheckState(Qt::Checked);
QStandardItem * item2 = new QStandardItem("xxx");
section->appendRow(QList<QStandardItem*>() << item << item2);
QComboBox * combo = new QComboBox();
QModelIndex index = m_model->index(j, 1, );
// HERE i have index = {-1;-1}
ui->treeView_options->setIndexWidget(index, combo);
}
m_model->appendRow(section);
}
Run Code Online (Sandbox Code Playgroud)
是否有可能以这种方式使用setIndexWidget?
更新:
我在第二栏中没有QComboBox ...为什么?
实际上是可能的.我建议先创建一个包含两列的模型.连续创建项目并将其附加到模型.只有在您view->setIndexWidget()使用组合框内容附加了可以调用的项目的行之后.它对我有用,我有动态内容.ItemDelegates更复杂,我建议setIndexWidget()- 为我工作就好了.