Domanda

Ho un QTableWidget e non riesco a ottenere nulla di presentarsi in esso.

I seguenti appare nel costruttore della finestra principale:

ui->tableWidget->setItem(0,0,new QTableWidgetItem("Item1"));
ui->tableWidget->setItem(0,1,new QTableWidgetItem("Item2"));
ui->tableWidget->setItem(0,2,new QTableWidgetItem("Item3"));

Quando eseguo l'applicazione, il widget tavolo si presenta, ma gli elementi non lo faccio.

Ho provato ad aggiungere ui->tableWidget->insertRow(0); prima che il codice di cui sopra, ma non ha funzionato.

È stato utile?

Soluzione

Aha! Ho capito che cosa stava succedendo ... avevo bisogno di raccontare il controllo il numero di righe che dovrebbe avere:

ui->tableWidget->setRowCount(2);

Altri suggerimenti

Esempio di codice:

//this will give the present number of rows available.
int insertRow = ui->tableWidget->rowCount();

//insert the row at the bottom of the table widget - using.
ui->tableWidget->insertRow(insertRow);

//After a new row is inserted we can add the table widget items as required.
ui->tableWidget->setItem(insertRow,0,new QTableWidgetItem("Item1"));
ui->tableWidget->setItem(insertRow,1,new QTableWidgetItem("Item2"));
ui->tableWidget->setItem(insertRow,2,new QTableWidgetItem("Item3"));
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top