Sunday, January 22, 2012

Qt Tutorial #1-3 Family Values

This is from Qt Tutorial #1 - Family Values


#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'''
    PyQt4 conversion of Qt Tutorial 3
    
    The original example uses a QVBox; a layout class with resize() and show() methods.
    In PyQt4 this is implemented as QVBoxLayout and there are no resize() or show() methods.
    To get same effect:
            create a QWidget
            set its layout to a QVBoxLayout
            add the QPushButton to the QVBoxLayout
            show the widget
    
last modified: 2012-01-19 jg
ref: http://doc.trolltech.com/3.3/tutorial1-03.html
'''

import sys
from PyQt4.QtGui import (QApplication, QWidget, QPushButton, QFont, QVBoxLayout)

def main():
    app = QApplication(sys.argv)    # required

    w = QWidget()
    w.resize(200, 120)

    vbox = QVBoxLayout()    # no resize() or show() methods
    w.setLayout(vbox)

    quitBtn = QPushButton('Quit')
    quitBtn.resize(75, 35)
    quitBtn.setFont(QFont("Times", 18, QFont.Bold))
    vbox.addWidget(quitBtn)

    quitBtn.clicked.connect(app.quit)  # register event handling

    w.show()
    sys.exit(app.exec_())   # start main event loop, exit when app closed

if __name__ == '__main__':
    main()