Is there a way to link or share a QTableWidgetItem between different QTableWidgets



  • Is there a way to link or share a QTableWidgetItem between different QTableWidgets

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

    Sample 1

    Sample 2

    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 tableWidget, 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.

    I could use the signal

    void QTableWidget::cellChanged(int row, int column)

    But then if the user had sorted on one of the Tabs, the Row and Column numbers won't match anymore on every Tab.

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

    Can anyone point me in the correct direction?

    By the way, whats the difference between

    void QTableWidget::cellChanged(int row, int column)

    and

    void QTableWidget::itemChanged(QTableWidgetItem

    Because I've been able to use QTableWidget::cellChanged correctly but I've no idea how to use QTableWidget::itemChanged, how do you use it, an example please.

    Thanks a lot for your time.


  • Qt Champions 2017

    The QTableWidget is item-based. meaning you insert the data into the widget and it takes control of it. (owns it)
    So sharing between QTableWidgets is not really working.

    However, the QTableView is a view-model object.
    Here your data lives in a object (the model) that the QTableView asks for data.

    It is possible to share this model between QTableViews and if you
    update any field, it would be the same for all as "playername" would only exists once.

    So if you have not,please read about QTableView and Qt's model/view framework.

    If only player name is shared, then using a model might be a bit overkill. Still super flexible.



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.