当前位置:网站首页>QTabelWidget实例
QTabelWidget实例
2022-04-22 09:26:00 【GoKu~】
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTableWidget>
#include <QTime>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->tableWidget->setColumnCount(3);
QStringList header;
header<<"序号"<<"时间"<<"内容";
ui->tableWidget->setHorizontalHeaderLabels(header);
ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);//表头宽度不可拖动变化
ui->tableWidget->setColumnWidth(0,100);
ui->tableWidget->setColumnWidth(1,200);
ui->tableWidget->horizontalHeader()->setSectionResizeMode(2,QHeaderView::Stretch);//最后一列自动拓展
ui->tableWidget->verticalHeader()->setVisible(false);//隐藏表头编号
ui->tableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter);//设置表头默认左对齐
ui->tableWidget->horizontalHeaderItem(0)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);//设置第一列居中对齐
ui->tableWidget->horizontalHeaderItem(1)->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);//设置第二列右对齐
ui->tableWidget->horizontalHeader()->setFont(QFont("黑体",16));//设置表头字体
ui->tableWidget->setAlternatingRowColors(true);//颜色交替
insertTabelItem();//显示编号
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::insertTabelItem(void)
{
QTableWidgetItem *item[3];
int i ,count;
for(i = 0;i<100;i++){
count = ui->tableWidget->rowCount();
ui->tableWidget->insertRow(count);
item[0] = new QTableWidgetItem(QString("%1").arg(i+1));
ui->tableWidget->setItem(i,0,item[0]);
QDateTime date =QDateTime::currentDateTime();
QString current_date =date.toString("yyyy.MM.dd hh:mm:ss");
item[1] = new QTableWidgetItem(current_date);
ui->tableWidget->setItem(i,1,item[1]);
item[2] = new QTableWidgetItem("变频器故障");
ui->tableWidget->setItem(i,2,item[2]);
}
}
执行:

版权声明
本文为[GoKu~]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_43517257/article/details/123171431
边栏推荐
- Starting from the needs of popular science, doctor training and promotion of innovative medical equipment products, how does "baiyihua" layout medical visualization SaaS services?
- (CVPR-2014)通过预测 10,000 个类别的深度学习人脸表示
- 从科普、医生培训及创新医械产品推广需求出发,「佰医绘」如何布局医学可视化SaaS服务?
- 云数引领下,桑达股份2021年营收427.04亿元,同比增长33.21%
- LeetCode 447. 回旋镖的数量 (排列组合问题)
- Unicorn Bio筹集320万美元资金 将用于培养肉的原型设备变成商业产品
- 网络抖动工具clumsy
- 如何保障缓存和数据库的一致性(超详细案例)
- 安装Navicat 15 详解及相关问题详解
- Write a simple examination program to complete the interaction of questions and answers on the console. Questions are divided into single choice and multi choice.
猜你喜欢

Design example of large range continuous adjustable (0 ~ 45V) low power stabilized voltage power supply based on MOSFET control

深度解析MOS管的GS波形分析-KIA MOS管

量化投资学习——介绍orderflow

经典场效应管如何快速关断技巧-KIA MOS管

mysql C语言连接

从辩证法角度,如何认知产品

MySQL uses the source command to import SQL. There is an error. I think it should be a coding problem. I don't know how to solve it

idea中如何将Services调出并将启动类显示在Services中

聊聊限流

ERP 集成对公司系统完善的重要性
随机推荐
uni-app项目之 请求的二次封装
esp-01s在arduino中的开发(一)
【谈思生物直播课】——湖景生物王子元博士关于基因治疗乙肝的探索
hyperscan --- 1
2022-04-21 mysql-innodb存储引擎核心处理
Open source, not just coding
L3-002 特殊堆栈 (30 分) (二分 栈
sqlserver 数据传输到 mysql
ShardingSphere分库分表
加密压缩备份BAT脚本
L2-030 冰岛人 (25 分) (最近公共祖先 思维
IOS开发之——数据库-基础知识介绍(01)
新书推荐——IPv6技术与应用(锐捷版)
openlayer中,svg图片无width如何修改大小
Write a simple examination program to complete the interaction of questions and answers on the console. Questions are divided into single choice and multi choice.
C#导入详细内容
Quantitative investment learning -- Introduction to orderflow
树莓派Kali系统 HDMI 修改屏幕分辨率
Manually build hyperledger fabric v2 X production network (IV) create channel and chain code life cycle
L2-004 search tree judgment