Unsolved Setting QTableWidgetItem background color with QComboBox on mac
-
Hello!
I am trying to set the background color of a QTableWidget item when QComboBox is set as the cell widget on mac (see attached screenshot). The other table items honor the palette's background color just fine, but this one does not. Help?
def setBackground(w, c): p = QPalette(w.palette()) w._orig_bg = p.color(QPalette.Window) w.setAutoFillBackground(True) p.setColor(QPalette.Window, c) w.setPalette(p) self.item(row, iDate).setBackground(bc) self.item(row, iDescription).setBackground(bc) self.item(row, iLogged).setBackground(bc) self.item(row, iPerson).setBackground(bc)
-
Hi,
The cell widget doesn't care about the cell underneath as it is not part of the cell. You may have to do some custom painting.
However, do you really need that combo box shown permanently rather than as an editor when editing the cell content ?
-
@SGaist You know, I actually don't need it to be permanent and the table would probably perform better if I didn't show comboboxes. Thanks...
-
@SGaist said in Setting QTableWidgetItem background color with QComboBox on mac:
Hi,
The cell widget doesn't care about the cell underneath as it is not part of the cell. You may have to do some custom painting.
Does that mean that the white is coming from the QComboBox or the cell widget? Seems like a QComboBox doesn't draw a background, at least in Creator?
-
The combo box is the cell widget. IIRC, you can use a style sheet to change the background colour of your cell widget.
But as you noted, you will indeed have a performance impact using cell widgets.
-
@SGaist said in Setting QTableWidgetItem background color with QComboBox on mac:
The combo box is the cell widget. IIRC, you can use a style sheet to change the background colour of your cell widget.
I guess I am not sure how to use a stylesheet to set the background color for the QComboBox on mac, as setting the "background" property via css overrides the entire mac style for the widget.
I also noticed that the QListView correctly draws the background color for the selected row. It's just when I set QPalette.Window using QWidget::setPalette() and the row is unselected that it doesn't work (see attached screenshot). So this is possible, somehow.
-
It's not the same properties that are used to render the selection rectangle and standard items. You'd likely have to dig a bit in Qt's internals to find out the differences. But again, using the combo box only as an editor is a better idea in terms of performance.