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)

Creating the main window


As a first step, we will start with creating a main window by subclassing the QMainWindow class. The QMainWindow class has a constructor function that is similar to the QWidget class:

PySide.QtGui.QMainWindow([QWidget * parent = 0, Qt::WindowFlags flags = 0)

The parent can be any valid QWidget object, and flags can be a valid combination of Qt.WindowFlags. The following code excerpt explains how to create a main window application at a very basic level:

# Import required modules
import sys, time
from PySide.QtGui import QMainWindow,QApplication

# Our main window class
class MainWindow(QMainWindow):
    # Constructor function
    def __init__(self):
        super(MainWindow,self).__init__()
        self.initGUI()


    def initGUI(self):
        self.setWindowTitle("Main Window")
        self.setGeometry(300, 250, 400, 300)
        self.show()

if __name__ == '__main__':
    # Exception Handling
    try:

        myApp = QApplication(sys.argv)
        mainWindow = MainWindow...