Ok, here's an example of some example code I've used with a sub class of a table model. I got the code from some example an muddled through getting the background color to change based on the value of the table cell.
But, I don't fully understand what is happening in the "data" method when the role is DisplayRole (I didn't change that part of the elif, it came with the example. (Why does the DisplayRole return code return empty QVariants?)
Again, from the example, the "setData" is as it came with the example (even the comment) and I'm getting data in my table so it's getting set elsewhere (actually, in the init for my sub class). So, is this method needed? And why would this have a role associated?
And why does "headerData" return an empty QVariant when the role isn't DisplayRole?
def data(self, index, role):
if not index.isValid():
elif role == Qt.BackgroundColorRole:
if self.arraydata[index.row()][7] == 'Stage':
...
elif role != QtCore.Qt.DisplayRole:
return QtCore.
QVariant(self.
arraydata[index.
row()][index.
column()])
def setData(self, index, value, role):
pass # not sure what to put here
def headerData(self, col, orientation, role):
if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
return QtCore.
QVariant(self.
headerdata[col
])
def data(self, index, role):
if not index.isValid():
return QVariant()
elif role == Qt.BackgroundColorRole:
if self.arraydata[index.row()][7] == 'Stage':
...
elif role != QtCore.Qt.DisplayRole:
return QtCore.QVariant()
return QtCore.QVariant(self.arraydata[index.row()][index.column()])
def setData(self, index, value, role):
pass # not sure what to put here
def headerData(self, col, orientation, role):
if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
return QtCore.QVariant(self.headerdata[col])
return QtCore.QVariant()
To copy to clipboard, switch view to plain text mode
Bookmarks