QStyledItemDelegate - get table item's current background color?
Unsolved
General and Desktop
-
Hello,
Trying to implement a transparent selection by using a QStyledItemDelegate and overriding the paint method:
def paint(self, painter, option, index): painter.save() if option.state & QtWidgets.QStyle.State_Selected: var = index.model() color = var.data(index, QtCore.Qt.BackgroundRole) text = var.data(index, QtCore.Qt.DisplayRole) painter.fillRect(option.rect, color.color()) painter.drawText(option.rect, QtCore.Qt.AlignCenter, text) else: QtWidgets.QStyledItemDelegate.paint(self, painter, option, index) painter.restore()
My table item, from a
TableWidget
, already has a color set (blue). So how can I get the current background of the cell and set the selected color to that? Settingcolor.color()
gives me a black background and just using the QBrush itselfcolor
gives me the default grey.(Text is slightly off too, I'd prefer to have it maintain its original settings)
-
Hi,
Do you mean you don't want to paint anything special when the item is selected ?
-
-
What style of border ?