TableWidget.cpp
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
//TableWidget控件
//设置列数
ui->tableWidget->setColumnCount(3);
//设置水平表头
ui->tableWidget->setHorizontalHeaderLabels(QStringList()<<"姓名"<<"性别"<<"年龄");
//设置行数
ui->tableWidget->setRowCount(5);
//设置正文
QStringList str;
str<<"牛魔"<<"关于"<<"张三"<<"里斯"<<"王五";
QList<QString>l;
l<<"男"<<"男"<<"男"<<"男"<<"男";
for(int i=0;i<5;++i)
{
int count=0;
ui->tableWidget->setItem(i,count++,new QTableWidgetItem(str[i]));
ui->tableWidget->setItem(i,count++,new QTableWidgetItem(l[i]));
ui->tableWidget->setItem(i,count++,new QTableWidgetItem(QString::number(i+18)));
}
}
Widget::~Widget()
{
delete ui;
}