效果图:
头文件:
QStandardItemModel *m_treeMode;
源文件
m_treeMode = new QStandardItemModel(0,1,this);
ui->treeView->setModel(m_treeMode);
//控制第一列节点个数
int mainLevel = 3;
for (int i = 0; i < mainLevel; ++i) {
QList<QStandardItem *> items;
//控制有列个数
int LevelCount = 5;
for (int i = 0; i < LevelCount; ++i){
QStandardItem *item = new QStandardItem(QString("%0").arg(i));
//控制可选择框
item->setCheckable(false);
items.push_back(item);
}
m_treeMode->appendRow(items);
// 设置内层行数
for (int i = 0; i < 2; ++i){
QList<QStandardItem *> childItems;
//设置内层列数
for (int i = 0; i < 5; ++i){
QStandardItem *item = new QStandardItem(QString("neibu"));
item->setCheckable(true);
childItems.push_back(item);
}
items.at(0)->appendRow(childItems);
}
}