QAbstractTableModel
-
wrote on 3 Sept 2024, 19:01 last edited by
Hello
I have used QAbstractTableModel to display some data in a QTableView and it works fine.
I just don't understand how the data method works and its really annoying me.
def data(self, QModelIndex, role= QtCore.Qt.DisplayRole): It seems to me like there should be a loop that goes through each QModelIndex row and QModelIndex column but in this method only one line is needed. to do this. Is this what is happening under the hood? if role == QtCore.Qt.DisplayRole: try: return self.data[QModelIndex.row()][QModelIndex.column()] except IndexError: return ""
-
Hi,
The index parameter gives you the positional information: row and column.
The role gives you which type of data is expected to get returned. If covers the data itself but also hints about how it should be rendered such as foreground and background color, associated decoration etc. That the delegate can use to do its work. -
Hi,
The index parameter gives you the positional information: row and column.
The role gives you which type of data is expected to get returned. If covers the data itself but also hints about how it should be rendered such as foreground and background color, associated decoration etc. That the delegate can use to do its work.wrote on 3 Sept 2024, 19:41 last edited by@SGaist Thanks for explaining but isn't there a loop going on to fill each row and column with the data?
-
The view(s) will request the data as required.
-
wrote on 3 Sept 2024, 19:46 last edited by
@SGaist Ahh ok yes i think i get it now.
Thank you
-
1/5