May 2019
Intermediate to advanced
542 pages
13h 37m
English
As you learned earlier in this chapter, widget colors are not properties of the widget – rather they are properties of the palette. The palette cannot be animated, because QPalette is not a subclass of QObject, and because setColor() requires more than just a single value.
Colors are something that we'd like to animate, though; to make that happen, we need to subclass our widget and make its color settings into Qt properties.
Let's do that with a button; start a new class at the top of the script, as follows:
class ColorButton(qtw.QPushButton): def _color(self): return self.palette().color(qtg.QPalette.ButtonText) def _setColor(self, qcolor): palette = self.palette() palette.setColor(qtg.QPalette.ButtonText, qcolor) self.setPalette(palette) ...
Read now
Unlock full access