0
votes

Qt Several tableWidgets share linked Items

Hi, in Qt I have a QMainWindow -> centralWidget (QWidget) -> QtabWidget -> then 10 Tabs (QWidgets) -> each with up to 26 QtableWidgets:

Sample 1

Sample 2

The idea is that instead of this:

    void MainWindow::on_pushButton_Add_Player_clicked()
{
     ui->tableWidget_Players->insertRow(ui->tableWidget_Players->rowCount());
     ui->tableWidget_Defensive->insertRow(ui->tableWidget_Defensive->rowCount());
     .
     . [10 tableWidgets in Total]
     .
     ui->tableWidgetAll->insertRow(ui->tableWidget_Players->rowCount());
}

Is there a way so that I can add a column each time to every tableWidget with less code.

Of course that's not there is to it, in fact I want to know is there is a way to link some of the Items of each that are actually the same Item but it's repeated in each like for example the Player Name is the same per row in each tableWidget, so if the user edits the name in one, it should change it in the same row in every tableWidget.

Is there a way to link them somehow, or the only way it's checking for item changes as signals.

I would also like that if I sort by column in one tableWidget, the new arrangement of the rows should be the same in every tableWidget.

Can anyone point me in the correct direction, the only idea I have it's using signals for ItemChanged. Isn't there a better way?

Thanks a lot for your time.

1

1 Answers

0
votes

If your tables are the same data, you should consider getting some nice model view controller action going (also say that phrase a lot when applying for jobs, they like that ;))

To do this you need to create a tablemodel. And a TableView widget. This way, the data is shared, so it exists in only one place. All your TableViews just show the data. You can have a look at QSortedFilterProxy to filter your data for a specific view(i have never used this, so don't know). That way you have your playerModel somewhere, and each view has a proxyModel that only shows for instance the active players.