In this section we see an implementation of a customized widget.
To start with we define the
AnalogClock class inherited from
QWidget. We define two variables that would be used for drawing the
minuteHand of the analog clock. Also, we define the colors for the pointers.
class AnalogClock(QWidget): hourHand = QPolygon([ QPoint(7, 8), QPoint(-7, 8), QPoint(0, -40) ]) minuteHand = QPolygon([ QPoint(7, 8), QPoint(-7, 8), QPoint(0, -70) ]) hourColor = QColor(255, 0, 127) minuteColor = QColor(0, 127, 127, 255) Next, we define an init function that will start the timer that would update the clock on expiry of every minute. It also resizes the widget and sets a title for it. def __init__(self, parent=None): QWidget.__init__(self) ...