Monday, January 23, 2012

Qt 4.8 Notepad Tutorial - Part 1

The following code is based on the Qt Getting Started Programming with Qt Hello Notepad tutorial. There are five parts in all.



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

'''
    PyQt4 conversion of Qt Tutorial 'Hello Notepad'
    
    In this first example, we simply create and show a text edit in a window 
    frame on the desktop. This represents the simplest possible Qt program 
    that has a GUI.
    
    NOTES:
    =====
    Every Qt GUI application must have one, and only one, QApplication
    instance; it is responsible for managing the application resources
    and the event thread.
    
last modified: 2012-01-23 jg
ref: http://developer.qt.nokia.com/doc/qt-4.8/gettingstartedqt.html
'''
import sys
from PyQt4.QtGui import (QApplication, QTextEdit)

def main():
    app = QApplication(sys.argv)    # required for all GUI applications

    te = QTextEdit()
    te.setText("This is a QTextEdit.")
    te.show()                       # make me visible

    sys.exit(app.exec_())           # start main event thread

if __name__ == '__main__':
    main()