QTableWidget + setCellWidget(myWidget) how remove from Cell without delete myWidget ?
-
wrote on 23 May 2016, 10:39 last edited by
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?wrote on 23 May 2016, 10:46 last edited by@pdn_mail
Hi,
You may try http://doc.qt.io/qt-4.8/qtablewidget.html#takeItem -
wrote on 23 May 2016, 10:54 last edited by
it hardly, takeItem works with QTableWidgetItem, but not with QWidget. Different mechanisms.
-
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 }
-
wrote on 24 May 2016, 03:44 last edited by pdn_mail
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
2/6