My paint code looks like this:
def paint(self, painter: QtGui.QPainter, option: QtWidgets.QStyleOptionViewItem, index: Union[QtCore.QModelIndex, QtCore.QPersistentModelIndex]) -> None:
painter.save()
model = self.parentObject.model()
sourceModel = model.sourceModel()
sourceIndex = model.mapToSource(index)
item = sourceModel.itemFromIndex(sourceIndex)
label = self.getLabel(item)
assert label
opt = QtWidgets.QStyleOptionButton()
opt.initFrom(label)
opt.rect = option.rect.adjusted(self.padding, self.padding, -self.padding, -self.padding)
opt.icon = label.icon()
opt.text = label.text()
opt.iconSize = label.iconSize()
option.widget.style().drawControl(QtWidgets.QStyle.ControlElement.CE_PushButton, opt, painter, label)
painter.restore()
Shouldn't the background color for the item already be painted with the correct color? The alternateColor and hover color for the item are properly painted because I get into this function. Only the select color is not painted properly.