# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1567982599 14400 # Node ID 2e9f6582c3d22cbf419f65ec9450bb937c7e223e # Parent 4a4c74d920bcb7a5bd65c9cca69c1297df06d8e7 ColourButton: use complete CSS instead overriding platfrom style This is as suggested by this answer: https://stackoverflow.com/a/57846090/11352427 Seems like it's still possible to override system styles as long as we set all parts of the CSS. The key seems to be to also set the radius so that Qt will recolour the button. diff --git a/tilerswift b/tilerswift --- a/tilerswift +++ b/tilerswift @@ -4,7 +4,6 @@ from colors import NES_PALETTE -PLASTIQUE = QtWidgets.QStyleFactory().create("Plastique") def read_rom(filename): with open(filename, 'rb') as f: @@ -279,20 +278,28 @@ self.colour_idx = colour_idx self.set_colour(colour_idx) - # Native styles sometimes don't allow recolouring the - # background, see https://bugreports.qt.io/browse/QTBUG-11089 - self.setStyle(PLASTIQUE) - def set_colour(self, colour_idx): self.colour_idx = colour_idx self.setText(f"{colour_idx:0{2}X}") bgcolour = NES_PALETTE[colour_idx] qt_colour = QtGui.QColor(bgcolour) - [r, g, b] = qt_colour.red(), qt_colour.green(), qt_colour.blue() + r, g, b = qt_colour.red(), qt_colour.green(), qt_colour.blue() luminance = (0.2126*r + 0.7152*g + 0.0722*b)/256 textcolour = 'white' if luminance < 0.5 else 'black' - self.setStyleSheet(f"color: {textcolour}; background-color: {bgcolour}") + bordercolour = "#444444" if r == g == b == 0 else qt_colour.darker().name() + self.setStyleSheet( + f''' + QPushButton {{ + color: {textcolour}; + background: {bgcolour}; + border: 2px outset {bordercolour}; + border-radius: 4px; + }} + QPushButton:pressed {{ + border-style: inset; + }}''' + ) class PaletteButton(ColourButton):