QTableWidget + setCellWidget(myWidget) how remove from Cell without delete myWidget ?
-
-
Hi!
I insert single myWidget to QTableWidget by setCellWidget().
When I using removeCellWidget() function myWidget is removed for ever, but it still will be necessary to me repeatedly.
How correctly remove from Cell myWidget without delete myWidget? -
Hi!
I insert single myWidget to QTableWidget by setCellWidget().
When I using removeCellWidget() function myWidget is removed for ever, but it still will be necessary to me repeatedly.
How correctly remove from Cell myWidget without delete myWidget?@pdn_mail
There is no way - currently.
The index widget will be deleted whenever a new index widget is set.
removeCellWidget() simply sets a NULL-widget. So you have implicitly the same problem.What exactly is your usecase?
An alternative would be to add a container widget. for example: QStackedWidget
And add the widgets there, so Qt doesn't delete them.if( QStackedWidget* w = qobject_cast<QStackedWidget*>( tableWidget->cellWidget(r,c) ) { w->addWidget( ... ) // set widget w->removeWidget( ... ); //remove widget w->setCurrentIndex( ... ) / w->setCurrentWidget( ... ); //switch widgets }
-
Thanks. But unfortunately I have other usecase, I shouldn't replace widgets in a cell, I should return to a cell initial properties which were to setCellWidget.
void MainWindow::on_tableWidget_cellEntered(int row, int column) { QStackedWidget *sw=new QStackedWidget; int r=cellwidgetcoord.row; int c=cellwidgetcoord.column; cellwidgetcoord.row=row; cellwidgetcoord.column=column; ui->tableWidget->removeCellWidget(r,c); sw->addWidget(&comboBox_5); ui->tableWidget->setCellWidget(row, column, sw); }
-
Thanks. But unfortunately I have other usecase, I shouldn't replace widgets in a cell, I should return to a cell initial properties which were to setCellWidget.
void MainWindow::on_tableWidget_cellEntered(int row, int column) { QStackedWidget *sw=new QStackedWidget; int r=cellwidgetcoord.row; int c=cellwidgetcoord.column; cellwidgetcoord.row=row; cellwidgetcoord.column=column; ui->tableWidget->removeCellWidget(r,c); sw->addWidget(&comboBox_5); ui->tableWidget->setCellWidget(row, column, sw); }
@pdn_mail
maybe it's enough to simply hide it