O'Reilly logo

PySide GUI Application Development by Venkateshwaran Loganathan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Custom widgets

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 hourHand and 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) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required