QT4编程之 - QTableWidget的运用

    QTableWidget可以�@示一��表格元件,表格中每���Υ娓�t�橐��QTableWidgetItem的��例,QTableWidgetItem要安插至表格中哪���Υ娓瘢��t是依索引的指定��Q定。
 
    下面的程式�a�楹��蔚�QTableWidget�cQTableWidgetItem的示�:  
 

 

 

#include <QApplication>
#include <QTableWidget>
#include <QHBoxLayout>

int main(int argc, char *argv[]) {
QApplication app(argc, argv);

QTableWidget *tableWidget = new QTableWidget;
tableWidget->setWindowTitle("QTableWidget & Item");
tableWidget->resize(350, 200);
tableWidget->setRowCount(10);
tableWidget->setColumnCount(5);

QStringList header;
header.append("Month");
header.append("Description");
tableWidget->setHorizontalHeaderLabels(header);

tableWidget->setItem(0, 0, new QTableWidgetItem("January"));
tableWidget->setItem(1, 0, new QTableWidgetItem("February"));
tableWidget->setItem(2, 0, new QTableWidgetItem("March"));

tableWidget->setItem(0, 1,
new QTableWidgetItem(QIcon("caterpillar_head.jpg"), "caterpillar's month"));
tableWidget->setItem(1, 1,
new QTableWidgetItem(QIcon("momor_head.jpg"), "momor's month"));
tableWidget->setItem(2, 1,
new QTableWidgetItem(QIcon("bush_head.jpg"), "bush's month"));

tableWidget->show();

return app.exec();
}


使用setItem()�r必�指定�Υ娓袼饕�值,索引�榱校�row)行(column),皆��0�_始,最左上角即�樗饕�(0, 0)位置。QTableWidgetItem也可以�O置�D片或核取��B(setCheckState())等。
 
下�D�槌淌�绦�r的��面:
 

你可能感兴趣的:(编程,职场,休闲,QT4,QTableWidget)