Introduction to PyQt4
Check out the new site at https://rkblog.dev.
14 July 2008
Comments
Creating an application in PyQT4 may be done in a few ways. The most common one is to use QTDesigner, which we get with QT. QTDesigner let us draw the GUI which is very handy for complicated interfaces. We can place widgets on the window, add names etc. To create an application in PyQT4 you have to:
- Create the GUI in QTDesigner
- Set names in the Property Editor to ease coding of the application (QTDesigner)
- Using pyuic4 create the python GUI class
- Call the application using that GUI class
- Extend it with our own slots
- When you use a widget you go to PyQt's Classes and check methods of each used widgets. The method names as "setText" are very easy to understand.
Tutorials List
- Simple text editor in PyQT4
- Extending PyQT4 text editor
- QYolk I - List widgets in PyQt4
- QYolk II - Containers
- PyQT4 Text editor - final changes
- QYolk III - List of updates
- WebKit in PyQt - rendering web pages
- PyQt events
- QtSql in PyQt4 - handling databases
- QGraphicsView and QGraphicsScene
- QTimer - making timers in PyQt4
- QScintilla2 and PyQT4
- Making PyQt4 widgets with SIP
- PictureFlow - listing images in PyQt4
- Rendering PDF files in PyQt4 with pypoppler-qt4
Introduction
We start with a "Hello... Close Button". When you launch the QTDesigner you will be able to chose base window type:





pyuic4 test.ui > test_ui.py
Next create test.py file with the code:
import sys
from PyQt4 import QtCore, QtGui
from test_ui import Ui_Form
class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Form()
self.ui.setupUi(self)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())
python test.py
You will see our application, and when you click the button it will close.Notes
Ui_Form is the class name generated by pyuic4 the "Form" part is the name of the main window. You can change it in QTDesigner (we will do this in next tutorial). You have to change the objectName:
RkBlog
Check out the new site at https://rkblog.dev.
Comment article