第一种:使用QStringList方式
QString labels;
labels << QObject::tr("姓名") << QObject::tr("性别") << QObject::tr("身高") << QObject::tr("年龄");
table.setHorizontalHeaderLabels(labels);第二种:在自定义模型中实现headerData()
QVariant MyModel::headerData(int section, Qt::Orientation orientation, int role) const


{
if(role == Qt::DisplayRole && orientation == Qt::Horizontal)
return header[section]; // header为QStringList类型,用户自定义
return QAbstractTableModel::headerData(section, orientation, role);
}第三种:在模型中实现QTableView标题的修改
model->setHeaderData(0, Qt::Horizontal, tr("姓名"));
model->setHeaderData(1, Qt::Horizontal, tr("性别"));
model->setHeaderData(2, Qt::Horizontal, tr("身高"));
model->setHeaderData(3, Qt::Horizontal, tr("年龄"));
posted on 2011-11-16 15:56
再生的雄鹰 阅读(9704)
评论(0) 编辑 收藏 引用