首页 > 代码库 > QTableWidget笔记

QTableWidget笔记

1、QTableWidget继承自QTableView.

2、头文件:QTableWidget

3、简单使用:

#include "mainwindow.h"#include <QApplication>#include <QTableWidget>#include <QTableWidgetItem>int main(int argc, char *argv[]){    QApplication a(argc, argv);    QTableWidget table;    table.setColumnCount(3);    table.setRowCount(5);    QStringList headers;    headers<<"ID"<<"Name"<<"Age"<<"Sex";    table.setHorizontalHeaderLabels(headers);    table.setItem(0,0,new QTableWidgetItem(QString("001")));    table.setItem(1,0,new QTableWidgetItem(QString("002")));    table.setItem(2,0,new QTableWidgetItem(QString("003")));    table.setItem(3,0,new QTableWidgetItem(QString("004")));    table.setItem(4,0,new QTableWidgetItem(QString("005")));    table.setItem(1,1,new QTableWidgetItem(QString("china")));    table.show();    table.resize(400,300);    return a.exec();}

 

代码比较简单,运行效果如下:

QTableWidget笔记