How to clone/duplicate QTableWidget?
-
Hi,
I need to clone QTableWidget from one QDialog class to another. My end goal is to keep one window displaying the table and if necessary do some changes in the table through other window and later saving changes and saving the new table back. I have managed to open the table in other window but then it dissapears from the original window.
Getting the original QTableWidget:
QTableWidget* ViewResults::GetResultsTable() { return ui->tableWidget; }
Constructor of second class where trying to open the duplicate window:
ChangeResults::ChangeResults(QWidget *parent, ViewResults *viewResults) : QDialog(parent), ui(new Ui::ChangeResults) { ui->setupUI(this); ui->verticalLayout->addWidget(mViewResults->GetResultsTable()); }
Any help is appreciated, Thanks!
-
@Siiiim1119
NoQWidget
can be "clone/duplicate"d, widgets are not copyable. And a widget can only have one parent, so if you re-parent then, yes, it will disappear from where it was.You must recreate the widget from its original definition. If you want to preserve some attributes, like say size, you must copy those across,
For a
QTableWidget
it has its model built into it, so you cannot (easily) have another one access the same data/model. If you changed to using aQTableView
then you can have multiple instances of those all using the same model data, which sounds like what you want. -
Hi,
How do you intend to do these changes ?
From the looks of it, you should just share the model between the dialogs.