My QTableWidget doesn't want to let me add a title to a new row with the button
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 :
Code:
int row;
row = ui->tableWidget->rowCount();
ui->tableWidget->setRowCount(row +1);
Re: My QTableWidget doesn't want to let me add a title to a new row with the button
Can you post a minimal program that demonstrates the problem?
Re: My QTableWidget doesn't want to let me add a title to a new row with the button
Quote:
Originally Posted by
ChrisW67
Can you post a minimal program that demonstrates the problem?
Code:
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
|____|____|____|
|____|____|____|
|____|____|____|
|____|____|____|
Re: My QTableWidget doesn't want to let me add a title to a new row with the button
Quote:
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?
Re: My QTableWidget doesn't want to let me add a title to a new row with the button
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.
Code:
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