I'm attempting to do a display a table with an icon as the background for each cell (the cell values will be either true or false, and ultimately, I want a red icon for false and some other icon for true.)
(probably could do it with background color, but I wanted a bit more "look" to it...)
So I've got it displaying a icon, but, I can't seem to get it to just fill the cell.
I specifically set the cell height and width
self.tableView.setRowHeight(64), self.tableView.setColumnWidth(64)
self.tableView.setRowHeight(64), self.tableView.setColumnWidth(64)
To copy to clipboard, switch view to plain text mode
which doesn't seem to work. (It appears to size to the data)
And the icon is duplicated, but only partially shown (I can see the top part and the top left of the second copy.
The data and setdata methods from my model are shown below. (I can never figure out from the QT docs what I what's nice to do, what has to be done, the minimum requirements, etc. so these are probably far from complete...
)
def data(self, index, role): # Return data from the model
if not index.isValid():
print('Invalid index in MyModel>data')
elif role == QtCore.Qt.BackgroundRole:
retval
= QtGui.
QPixmap('/home/mac/SharedData/PycharmProjs/MuteMap/Mute_dark.png') elif role == QtCore.Qt.DisplayRole:
retval
= QtCore.
QVariant(self.
arraydata[index.
row()][index.
column()]) else:
return retval
def setData(self, index, value, role): # Set data in the model
if role == QtCore.Qt.EditRole and index.isValid():
print(index.row())
self.arraydata[index.row()][index.column()] = value
print('Return from rowCount: {0}'.format(self.rowCount(index)))
self.dataChanged.emit(index, index, [QtCore.Qt.DisplayRole])
return True
return False
def data(self, index, role): # Return data from the model
if not index.isValid():
print('Invalid index in MyModel>data')
retval = QtCore.QVariant()
elif role == QtCore.Qt.BackgroundRole:
retval = QtGui.QPixmap('/home/mac/SharedData/PycharmProjs/MuteMap/Mute_dark.png')
elif role == QtCore.Qt.DisplayRole:
retval = QtCore.QVariant(self.arraydata[index.row()][index.column()])
else:
retval = QtCore.QVariant()
return retval
def setData(self, index, value, role): # Set data in the model
if role == QtCore.Qt.EditRole and index.isValid():
print(index.row())
self.arraydata[index.row()][index.column()] = value
print('Return from rowCount: {0}'.format(self.rowCount(index)))
self.dataChanged.emit(index, index, [QtCore.Qt.DisplayRole])
return True
return False
To copy to clipboard, switch view to plain text mode
Bookmarks