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);
}


