Qt-Table Widget

端木澄邈
2023-12-01

相比Table View操作简单,显示数据量少:几百几千;

常用操作:

ui->tableWidget->setRowCount(4);//设置表格行数

ui->tableWidget->setColumnCount(2);//设置表格列数

ui->tableWidget->setHorizontalHeaderLabels(QStringList()<<tr“参数名"<< "参数值");//设置水平表头

ui->tableWidget->horizontalHeader()->setStretchLastSection(true);、//设置表头可拉伸

ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);//设置表头平均拉伸

ui->tableWidget->setAlternatingRowColors(true);//设置隔行换色

ui->tableWidget->verticalHeader()/horizontalHeader()->setVisible(false);//设置纵向表头/横向表头不可见

ui->tableWidget->setShowGrid(false);//设置表格框线隐藏

ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);//设置单元格不可编辑

ui->tableWidget->verticalHeader()/horizontalHeader()->setSectionsClickable(false);//设置表头不可点击

ui->tableWidget->setItem(0,0,new QTableWidgetItem(tr("MaxNum")));   //设置第0行第0列单元格内容

styleSheetQTabWidget::pane { border: 0; }//去除控件边框

 类似资料: