PDA

View Full Version : My QTableWidget doesn't want to let me add a title to a new row with the button



Martindb
15th March 2019, 13:40
I am creating a stock controlling system,but when I add the new row I can edit the product numbers and everything, except for the new product,please help.
Thank you in advance

my code :


int row;
row = ui->tableWidget->rowCount();
ui->tableWidget->setRowCount(row +1);

ChrisW67
16th March 2019, 23:07
Can you post a minimal program that demonstrates the problem?

Martindb
18th March 2019, 05:47
Can you post a minimal program that demonstrates the problem?



void BPW::on_pushButton_clicked(){

int row;
row = ui->tableWidget->rowCount();
ui->tableWidget->setRowCount(row + 1)

}



I hope this is what you needed..

Basically looks like the table below,but column 0 is not editable,from column 1 I can edit though

|____|____|____|
|____|____|____|
|____|____|____|
|____|____|____|

d_stranz
18th March 2019, 22:09
Basically looks like the table below,but column 0 is not editable,from column 1 I can edit though

Your code is adding a new row, so why are you complaining about columns?

The code you posted is basically no different from the code in your original post, and does nothing except add a new row to the table. Where is the complete code that fails when you try to do whatever it is you are trying to do with coolumns and titles?

Prodeine
20th March 2019, 00:50
try using this;

ui->tableWidget->insertRow(row)

count starts from 0 because nothing is there, row 0 is actually the index for the first item. every time you press the add button you will get a new line.


edit: you may also be trying to edit your headers, here is an example of something I am using right now.


void Resolver::on_pushButton_6_clicked()
{
ui->calcResults->clear();
ui->calcResults->setColumnCount(5);
m_TableHeader<<"Bet"<<"Balance"<<"Wager"<<"Payout"<<"Profit"; // is a QStringList
ui->calcResults->setHorizontalHeaderLabels(m_TableHeader);

......


int count = ui->calcResults->rowCount();
ui->calcResults->insertRow(count);

you will want to setVerticleHeaderLabels instead

https://doc.qt.io/qt-5/qtablewidget.html