#include <QApplication>
#include <QDebug>
#include <QListWidget>
#include <QTableWidget>
int main(int argc,char **argv)
{
QApplication app(argc,argv);
QListWidget listWidget;
//一种添加项目的简单方法
new QListWidgetItem("a",&listWidget);
new QListWidgetItem("c",&listWidget);
//添加项目的另一只种方法,这样可以进行各种设置
QListWidgetItem *listWidgetItem= new QListWidgetItem;
listWidgetItem ->setText("b");
listWidgetItem ->setIcon(QIcon("hehua.jpg"));
listWidgetItem ->setToolTip("this is b");
listWidget.insertItem(1,listWidgetItem);
//设置Item排序为倒序
listWidget.sortItems(Qt::DescendingOrder);
listWidget.show();
return app.exec();
}
QTreeWidget treeWidget;
//必须设置列数
treeWidget.setColumnCount(2);
//设置表头
QStringList headers;
headers << "name" << "year";
treeWidget.setHeaderLabels(headers);
//添加项目
QTreeWidgetItem *grade1 = new QTreeWidgetItem(&treeWidget);
grade1->setText(0,"Grade1");
QTreeWidgetItem *student = new QTreeWidgetItem(grade1);
student->setText(0,"tom");
student->setText(1,"1988");
QTreeWidgetItem *student2 = new QTreeWidgetItem(grade1);
student2->setText(0,"jerry");
student2->setText(1,"1987");
QTreeWidgetItem *grade2 = new QTreeWidgetItem(grade1);
grade2->setText(0,"Grade2");
QTreeWidgetItem *student3 = new QTreeWidgetItem;
grade2->addChild(student3);
student3->setText(0,"lilei");
student3->setText(1,"1990");
treeWidget.show();
/****************************/
//创建表格部件,同时指定行数和列数
QTableWidget tableWidget(3,2);
//创建表哥项目,并插入到指定单元
QTableWidgetItem *tableWidgetItem = new QTableWidgetItem("qt");
tableWidget.setItem(1,1,tableWidgetItem);
//创建表格项目,并将他们作为表头
QTableWidgetItem *headerV = new QTableWidgetItem("first");
tableWidget.setVerticalHeaderItem(0,headerV);
QTableWidgetItem *headerH = new QTableWidgetItem("ID");
tableWidget.setHorizontalHeaderItem(0,headerH);
tableWidget.show();
return app.exec();
}