How to add QPushButton to QTableWidget cell?
Code:
btn1->setParent(ui->tableStatus);
btn1
->setIconSize
((QSize(97,
25)));
btn1->setIcon(icon1);
btn1->setVisible(true);
ui->tableStatus->setCellWidget(0,3,btn1);
I have used the above code and it is not placing the button on the particular cell, It just attaches in the top left corner of the table widget.
Re: How to add QPushButton to QTableWidget cell?
This code works just fine here but the table needs at least one row and four columns.
Line 4 is a memory leak.
Line 7 is unnecessary and results in the problem you describe if the table does not contain at least one row, four columns. The widget cannot be put in the cell but you have parented it and made it visible so it shows as a child of the table (i.e. on top of the table widget).
Re: How to add QPushButton to QTableWidget cell?
I have already defined the row count as 16 and column count as 3 in constructor.
2 Attachment(s)
Re: How to add QPushButton to QTableWidget cell?
Then you are not telling us what you are really doing:
Code:
#include <QApplication>
#include <QTableWidget>
#include <QPushButton>
int main(int argc, char *argv[])
{
// Your code
btn1->setParent(tableStatus);
btn1
->setIconSize
((QSize(97,
25)));
btn1->setIcon(icon1);
btn1->setVisible(true);
tableStatus->setCellWidget(0,3,btn1);
// end of your code
tableStatus->show();
int ret = app.exec();
delete pixmap1;
delete tableStatus;
return ret;
}
Attachment 10285
Or, if you change line 19 to:
Code:
tableStatus->setCellWidget(0,5,btn1); // non-existent cell
Attachment 10286