QTableWidget* table = new QTableWidget( 3, 2 ); int i = 0; for ( ; i < 3; ++i ) { int j = 0; for ( ; j < 2; ++j ) { QTableWidgetItem* item = new QTableWidgetItem(); item->setText( QString( "(%1,%2)" ).arg( i ).arg( j ) ); table->setItem( i, j, item ); } }
ui.setupUi(this); ui.tableWidget ->setRowCount(20); ui.tableWidget ->setColumnCount(5); // шапка start /* QString arr[5]; arr[0]="authorName";arr[1]="bookName";arr[2]="year";arr[3]="publishingHouse";arr[4]="requestCount";*/ QStringList arr; arr << "authorName" << "bookName" << "year" << "publishingHouse" << "requestCount"; for(int i =0 ; i < 5; ++i) { QTableWidgetItem * lala = new QTableWidgetItem(arr[i]); ui.tableWidget->setHorizontalHeaderItem(i,lala); } // шапка end QString arr1[5]; arr1[0]="ivanov"; arr1[1]="physic"; arr1[2]="2005"; arr1[3]="tartar"; arr1[4]="16"; Kitap p1p("para","paraba",2,"mama",4); p1p.bookName; p1p.authorName; p1p.publishingHouse; p1p.year; p1p.requestCount; for(int i=0; i < 5 ; ++i) { QTableWidgetItem * lal1 = new QTableWidgetItem(arr1[i]); ui.tableWidget->setItem(0,i,lal1); } QTableWidgetItem * lal4 = new QTableWidgetItem(p1p.bookName); ui.tableWidget->setItem(1,0,lal4); QTableWidgetItem * lal5 = new QTableWidgetItem(p1p.authorName); ui.tableWidget->setItem(1,1,lal5); QTableWidgetItem * lal6 = new QTableWidgetItem(p1p.publishingHouse); ui.tableWidget->setItem(1,2,lal6); QTableWidgetItem * lal7 = new QTableWidgetItem(p1p.year); ui.tableWidget->setItem(1,3,lal7); QTableWidgetItem * lal8 = new QTableWidgetItem(p1p.requestCount); ui.tableWidget->setItem(1,4,lal8);
void MainWindow::on_pushButton_clicked(){QTableWidget *table = new QTableWidget(15,15,this);}
void MainWindow::on_pushButton_2_clicked(){table->setGeometry(10,10,500,500);}