#include "Widget.h"
#include "ui_Widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    // tableWidget 树控件的使用
    // 设置列数
    this->ui->tableWidget->setColumnCount(3);

    // 设置水平表头
    this->ui->tableWidget->setHorizontalHeaderLabels(QStringList() << "name" << "sex" << "age");

    // 设置行数
    this->ui->tableWidget->setRowCount(5);

    // 设置正文
    QStringList nameList;
    nameList << "tqz" << "xys" << "ctt" << "fhx" << "syl";

    QList<QString> sexList;
    sexList << "otoko" << "onnna" << "onnna" << "onnna" << "onnna";

    for (int i = 0; i < 5; i++) {
        int col = 0;
        this->ui->tableWidget->setItem(i, col++, new QTableWidgetItem(nameList[i]));
        this->ui->tableWidget->setItem(i, col++, new QTableWidgetItem(sexList.at(i)));
        this->ui->tableWidget->setItem(i, col++, new QTableWidgetItem(QString::number(19)));
    }
}

Widget::~Widget()
{
    delete ui;
}

Logo

加入社区!打开量化的大门,首批课程上线啦!

更多推荐