博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
QT中QTableWidget的使用
阅读量:6069 次
发布时间:2019-06-20

本文共 4444 字,大约阅读时间需要 14 分钟。

table.h

#ifndef TABLE_H#define TABLE_H#include 
#include "ui_table.h"class Table : public QTableWidget{ Q_OBJECTpublic: Table(); ~Table();private: Ui::TableClass ui;};#endif // TABLE_H

table.cpp

#include "table.h"Table::Table(): QTableWidget(){		setWindowTitle(tr("table"));	setColumnCount(5);	setRowCount(5);	QTableWidgetItem *tableWidgetItemSex=new QTableWidgetItem(tr("sex"));	setItem(0,0,tableWidgetItemSex);	QTableWidgetItem *tableWidgetItemName=new QTableWidgetItem(tr("Name"));	setItem(0,1,tableWidgetItemName);	QTableWidgetItem *tableWidgetItemBrith=new QTableWidgetItem(tr("Brith"));	setItem(0,2,tableWidgetItemBrith);	QTableWidgetItem *tableWidgetItemWork=new QTableWidgetItem(tr("Work"));	setItem(0,3,tableWidgetItemWork);	QTableWidgetItem *tableWidgetItemIncome=new QTableWidgetItem(tr("Income"));	setItem(0,4,tableWidgetItemIncome);	QLabel *LabelPixmap1 = new QLabel();	LabelPixmap1->setPixmap(QPixmap(":/images/Male.png"));	setCellWidget (1,0,LabelPixmap1);	QTableWidgetItem *TableWidgetItem1 = new QTableWidgetItem(tr("Tom"));	setItem(1, 1, TableWidgetItem1);		QDateTimeEdit *DateTimeEdit1= new QDateTimeEdit();	DateTimeEdit1->setDateTime(QDateTime::currentDateTime());	DateTimeEdit1->setDisplayFormat("dd/M/yyyy");	DateTimeEdit1->setCalendarPopup(true);	setCellWidget (1,2,DateTimeEdit1);			QComboBox *ComboBoxWork1 = new QComboBox();	ComboBoxWork1->addItem(tr("Worker")); 	ComboBoxWork1->addItem(tr("Farmer")); 	ComboBoxWork1->addItem(tr("Doctor")); 	ComboBoxWork1->addItem(tr("Lawyer")); 	ComboBoxWork1->addItem(tr("Soldier")); 	setCellWidget(1,3,ComboBoxWork1);	QSpinBox *SpiBoxIncome1 = new QSpinBox();	SpiBoxIncome1->setRange (1000,10000); 	setCellWidget(1,4,SpiBoxIncome1);	QLabel *LabelPixmap2 = new QLabel();	LabelPixmap2->setPixmap(QPixmap(":/images/Male.png"));	setCellWidget (2,0,LabelPixmap2);	QTableWidgetItem *TableWidgetItem2 = new QTableWidgetItem(tr("Jack"));	setItem(2, 1, TableWidgetItem2);		QDateTimeEdit *DateTimeEdit2= new QDateTimeEdit();	DateTimeEdit2->setDateTime(QDateTime::currentDateTime());	DateTimeEdit2->setDisplayFormat("dd/M/yyyy");	DateTimeEdit2->setCalendarPopup(true);	setCellWidget (2,2,DateTimeEdit2);			QComboBox *ComboBoxWork2 = new QComboBox();	ComboBoxWork2->addItem(tr("Worker")); 	ComboBoxWork2->addItem(tr("Farmer")); 	ComboBoxWork2->addItem(tr("Doctor")); 	ComboBoxWork2->addItem(tr("Lawyer")); 	ComboBoxWork2->addItem(tr("Soldier")); 	setCellWidget(2,3,ComboBoxWork2);	QSpinBox *SpiBoxIncome2 = new QSpinBox();	SpiBoxIncome2->setRange (1000,10000); 	setCellWidget(2,4,SpiBoxIncome2);	QLabel *LabelPixmap3 = new QLabel();	LabelPixmap3->setPixmap(QPixmap(":/images/Female.png"));	setCellWidget (3,0,LabelPixmap3);	QTableWidgetItem *TableWidgetItem3 = new QTableWidgetItem(tr("Alice"));	setItem(3, 1, TableWidgetItem3);		QDateTimeEdit *DateTimeEdit3= new QDateTimeEdit();	DateTimeEdit3->setDateTime(QDateTime::currentDateTime());	DateTimeEdit3->setDisplayFormat("dd/M/yyyy");	DateTimeEdit3->setCalendarPopup(true);	setCellWidget (3,2,DateTimeEdit3);			QComboBox *ComboBoxWork3 = new QComboBox();	ComboBoxWork3->addItem(tr("Worker")); 	ComboBoxWork3->addItem(tr("Farmer")); 	ComboBoxWork3->addItem(tr("Doctor")); 	ComboBoxWork3->addItem(tr("Lawyer")); 	ComboBoxWork3->addItem(tr("Soldier")); 	setCellWidget(3,3,ComboBoxWork3);	QSpinBox *SpiBoxIncome3 = new QSpinBox();	SpiBoxIncome3->setRange (1000,10000); 	setCellWidget(3,4,SpiBoxIncome3);	QLabel *LabelPixmap4 = new QLabel();	LabelPixmap4->setPixmap(QPixmap(":/images/Male.png"));	setCellWidget (4,0,LabelPixmap4);	QTableWidgetItem *TableWidgetItem4 = new QTableWidgetItem(tr("John"));	setItem(4, 1, TableWidgetItem4);			QDateTimeEdit *DateTimeEdit4= new QDateTimeEdit();	DateTimeEdit4->setDateTime(QDateTime::currentDateTime());	DateTimeEdit4->setDisplayFormat("dd/M/yyyy");	DateTimeEdit4->setCalendarPopup(true);	setCellWidget (4,2,DateTimeEdit4);			QComboBox *ComboBoxWork4 = new QComboBox();	ComboBoxWork4->addItem(tr("Worker")); 	ComboBoxWork4->addItem(tr("Farmer")); 	ComboBoxWork4->addItem(tr("Doctor")); 	ComboBoxWork4->addItem(tr("Lawyer")); 	ComboBoxWork4->addItem(tr("Soldier")); 	setCellWidget(4,3,ComboBoxWork4);	QSpinBox *SpiBoxIncome4 = new QSpinBox();	SpiBoxIncome4->setRange (1000,10000); 	setCellWidget(4,4,SpiBoxIncome4);	}Table::~Table(){}

main.cpp

#include "table.h"#include 
int main(int argc, char *argv[]){ QApplication a(argc, argv); Table *w=new Table; w->show(); return a.exec();}

转载地址:http://cwfgx.baihongyu.com/

你可能感兴趣的文章
程序员最喜爱的12个Android应用开发框架二(转)
查看>>
vim学习与理解
查看>>
DIRECTSHOW在VS2005中PVOID64问题和配置问题
查看>>
MapReduce的模式,算法以及用例
查看>>
《Advanced Linux Programming》读书笔记(1)
查看>>
zabbix agent item
查看>>
一步一步学习SignalR进行实时通信_7_非代理
查看>>
AOL重组为两大业务部门 全球裁员500人
查看>>
字符设备与块设备的区别
查看>>
为什么我弃用GNOME转向KDE(2)
查看>>
Redis学习记录初篇
查看>>
爬虫案例若干-爬取CSDN博文,糗事百科段子以及淘宝的图片
查看>>
Web实时通信技术
查看>>
第三章 计算机及服务器硬件组成结合企业运维场景 总结
查看>>
IntelliJ IDEA解决Tomcal启动报错
查看>>
默认虚拟主机设置
查看>>
七周五次课(1月26日)
查看>>
Linux系统一些系统查看指令
查看>>
php中的短标签 太坑人了
查看>>
[译] 可维护的 ETL:使管道更容易支持和扩展的技巧
查看>>