Book Image

Pyside GUI Application Development- Second Edition - Second Edition

By : Venkateshwaran Loganathan, Gopinath Jaganmohan
Book Image

Pyside GUI Application Development- Second Edition - Second Edition

By: Venkateshwaran Loganathan, Gopinath Jaganmohan

Overview of this book

Elegantly-built GUI applications are always a massive hit among users. PySide is an open source software project that provides Python bindings for the Qt cross-platform UI framework. Combining the power of Qt and Python, PySide provides easy access to the Qt framework for Python developers and also acts as an excellent rapid application development platform. This book will take you through everything you need to know to develop UI applications. You will learn about installing and building PySide in various major operating systems as well as the basics of GUI programming. The book will then move on to discuss event management, signals and slots, and the widgets and dialogs available with PySide. Database interaction and manipulation is also covered. By the end of this book, you will be able to program GUI applications efficiently and master how to develop your own applications and how to run them across platforms.
Table of Contents (13 chapters)

Custom widget


To start with, we define the AnalogClock class that is inherited from QWidget. We define two variables that will be used to draw the hourHand and minuteHand of the analog clock. We also 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 will update the clock on the expiry of every minute. It also resizes the widget and sets a title for it:

def __init__(self, parent=None):
        QWidget.__init__(self)

        timer = QTimer(self)
        timer.timeout.connect(self.update)
        timer.start(1000)

        self.setWindowTitle("Analog Clock")
        self.resize(200, 200)

The core functionality of the analog clock is defined...