Qt源代码实现表格QTableWidget

所需要的头文件

#include 
#include 

源文件是

 QTableWidget *ui_table = new QTableWidget(this);
    ui_table->setRowCount(3);   //设置表格是3行2列
    ui_table->setColumnCount(2);
    ui_table->setEditTriggers(QAbstractItemView::NoEditTriggers);  //设置为不可编辑
    ui_table->verticalHeader()->setVisible(false);   //设置行列头隐藏
    ui_table->horizontalHeader()->setVisible(false);
    ui_table->setFrameStyle(QFrame::NoFrame);

    QTableWidgetItem *table00 = new QTableWidgetItem;
    table00->setText(QStringLiteral("型号"));
    QTableWidgetItem *table01 = new QTableWidgetItem;
    table01->setText(QStringLiteral("camera"));
    QTableWidgetItem *table10 = new QTableWidgetItem;
    table10->setText(QStringLiteral("IP"));
    QTableWidgetItem *table11 = new QTableWidgetItem;
    table11->setText(QStringLiteral("192.168.1.1"));
    QTableWidgetItem *table20 = new QTableWidgetItem;
    table20->setText(QStringLiteral("在线数量"));
    QTableWidgetItem *table21 = new QTableWidgetItem;
    table21->setText(QStringLiteral("3"));

    ui_table->setItem(0,0,table00);
    ui_table->setItem(0,1,table01);
    ui_table->setItem(1,0,table10);
    ui_table->setItem(1,1,table11);
    ui_table->setItem(2,0,table20);
    ui_table->setItem(2,1,table21);

效果图

Qt源代码实现表格QTableWidget_第1张图片

你可能感兴趣的:(Qt,qt,ui,开发语言)