.h
#ifndef MYLABLE_H
#define MYLABLE_H
#include <QTableWidget>
#include <QLabel>
#include <QDateTimeEdit>
#include <QPushButton>
#include <QTableWidgetItem>
#include <QComboBox>
#include <QSpinBox>
class Mylable:public QTableWidget
{
Q_OBJECT
public:
Mylable();
public:
QLabel *LabelPixmap1;
QLabel *LabelPixmap2;
QTableWidgetItem *TableWidgetItem1;
QTableWidgetItem *TableWidgetItem2;
QDateTimeEdit *DateTimeEdit1;
QDateTimeEdit *DateTimeEdit2;
QComboBox *ComboBoxWork1;
QComboBox *ComboBoxWork2;
QSpinBox *SpiBoxIncome1;
QSpinBox *SpiBoxIncome2;
QTableWidgetItem *t1;
QTableWidgetItem *t2;
QTableWidgetItem *t3;
QTableWidgetItem *t4;
QTableWidgetItem *t5;
};
#endif
.c
#include "mylable.h"
Mylable::Mylable()
{
setWindowTitle("表格的使用");
setColumnCount(5);
setRowCount(3);
t1 = new QTableWidgetItem("头像");
t2 = new QTableWidgetItem("姓名");
t3 = new QTableWidgetItem("出生日期");
t4 = new QTableWidgetItem("职业");
t5 = new QTableWidgetItem("收入");
setItem(0,0,t1);
setItem(0,1,t2);
setItem(0,2,t3);
setItem(0,3,t4);
setItem(0,4,t5);
LabelPixmap1 = new QLabel();
LabelPixmap2 = new QLabel();
LabelPixmap1->setPixmap(QPixmap(":/aa.png"));
LabelPixmap2->setPixmap(QPixmap(":/cc.png"));
setCellWidget(1,0,LabelPixmap1);
setCellWidget(2,0,LabelPixmap2);
TableWidgetItem1 = new QTableWidgetItem("张三");
setItem(1,1,TableWidgetItem1);
TableWidgetItem2 = new QTableWidgetItem("李四");
setItem(2,1,TableWidgetItem2);
DateTimeEdit1 = new QDateTimeEdit;
DateTimeEdit1->setDateTime(QDateTime::currentDateTime());
DateTimeEdit1->setDisplayFormat("dd/M/yyyy");
DateTimeEdit1->setCalendarPopup(true);
setCellWidget(1,2,DateTimeEdit1);
DateTimeEdit2 = new QDateTimeEdit;
DateTimeEdit2->setDateTime(QDateTime::currentDateTime());
DateTimeEdit2->setDisplayFormat("dd/M/yyyy");
DateTimeEdit2->setCalendarPopup(true);
setCellWidget(2,2,DateTimeEdit2);
ComboBoxWork1 = new QComboBox();
ComboBoxWork2 = new QComboBox();
ComboBoxWork1->addItem("worker");
ComboBoxWork1->addItem("farmer");
ComboBoxWork1->addItem("doctor");
ComboBoxWork1->addItem("lawyer");
ComboBoxWork1->addItem("soldier");
ComboBoxWork2->addItem("doctor");
ComboBoxWork2->addItem("lawyer");
setCellWidget(1,3,ComboBoxWork1);
setCellWidget(2,3,ComboBoxWork2);
SpiBoxIncome1 = new QSpinBox();
SpiBoxIncome1->setRange(2000,10000);
setCellWidget(1,4,SpiBoxIncome1);
SpiBoxIncome2 = new QSpinBox();
SpiBoxIncome2->setRange(2000,10000);
setCellWidget(2,4,SpiBoxIncome2);
}
main.c
#include "mainwindow.h"
#include <QApplication>
#include "mylable.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Mylable b;
b.show();
return a.exec();
}
|