OK, let's see if I understand, I create a model that for example includes the Player Name, that would go in every Table Tab and will be the same so it's reflected in every Tab (view). Now I can add more to that base model right like sub-classes, right? So they all have Player Name but each Tab (view) has it's own Items.
Not quite. To implement your own model, you need to derive a class from QAbstractTableModel. In that class, you need to re-implement certain methods, like rowCount(), columnCount(), data(), index(), and optionally headerData(). If the model is editable, you need to implement setData() as well.
Presumably, you have your own data structure that represents your teams, players, or whatever it is. Your table model can contain a pointer to that data structure, or in some way have access to it.
rowCount() is going to return the number of players, for example. columnCount() is going to return the total number of columns of information for each player. data() can return a bunch of different things, depending on the value of the "role" argument that is passed in. For Qt:: DisplayRole, for example, if the player name goes in column 0, you will return the name of the first player when data() asks for the DisplayRole for the QModelIndex with row = 0 and column = 0. Row = 1, column = 0 is the name of the second player, and so forth.
You should study this tutorial.
If your tables each contain slightly different information (and why would you want 28 tables all with the same information?), then you can teach yourself about proxy models. You still have only a single base model that contains all of the information you might want to display anywhere, but you create a proxy model for use by a particular view to select out the subset of the information you want in a particular table. See QSortFilterProxyModelfor one.
But could you give me an example of how should the QTableWidgetItem pointer go on itemChanged(QTableWidgetItem * item)
I think maybe you are confused. This is a signal. The view emits the signal after the item is changed, and the signal contains the pointer to the item that was changed. You don't call this method, it gets connected to your slot. Your slot receives the pointer value as an argument, and you use it to determine which row and column was changed (item->row() and item->column()).
If you ignore the QTableWidgetItem pointer, then your code is assuming that it gets emitted only for column 0, when in fact it gets emitted any time the value in any cell gets changed. The value of the pointer tells you which cell it is.
//...
{
// do something with item
}
connect( myTableWidget, SIGNAL( itemChanged( QTableWidgetItem * ) ), myClass, SLOT( mySlot( QTableWidgetItem * ) ) );
//...
void MyClass::mySlot( QTableWidgetItem * item )
{
// do something with item
}
To copy to clipboard, switch view to plain text mode
Bookmarks