1 设置表头
QVariant QAbstractItemModel::headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
用法:
QVariant DockMessageModel::headerData(int section, Qt::Orientation orientation, int role /*= Qt::DisplayRole*/) const
{
/*return QString("ABC %1").arg(section);*/
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Horizontal)
return QString("Column %1").arg(section);
else
return QString("Row %1").arg(section);
}
2 其它设置,
this->setSelectionMode(QAbstractItemView::SingleSelection); // 只能选择一行
this->setSelectionBehavior(QAbstractItemView::SelectRows); //按行选
this->horizontalHeader()->setVisible(true); // 表头可见
this->horizontalHeader()->setStretchLastSection(true); // QTableview的函数,设置最后一列填充
this->verticalHeader()->setVisible(false);
3 获取edit后的表格或treeview的值
void QAbstractItemView::closeEditor(QWidget * editor, QAbstractItemDelegate::EndEditHint hint)
Closes the given editor, and releases it. The hint is used to specify how the view should respond to the end of the editing operation. For example, the hint may indicate that the next item in the view should be opened for editing.
本文详细介绍了如何使用QAbstractItemView和QTableView进行高级属性配置,包括设置表头、选择模式、显示行为、以及获取编辑后的表格或treeview的值。同时,提供了一个自定义表头数据的示例,并展示了如何关闭编辑器并释放资源。
1022

被折叠的 条评论
为什么被折叠?



