- PyQt5 - Discussion
- PyQt5 - Useful Resources
- PyQt5 - Quick Guide
- PyQt5 - QPixmap Class
- PyQt5 - QClipboard
- PyQt5 - BrushStyle Constants
- PyQt5 - Drawing API
- PyQt5 - Database Handling
- PyQt5 - Drag & Drop
- PyQt5 - Multiple Document Interface
- PyQt5 - QMessageBox
- PyQt5 - QDialog Class
- PyQt5 - Basic Widgets
- PyQt5 - Layout Management
- PyQt5 - Signals & Slots
- PyQt5 - Using Qt Designer
- PyQt5 - Major Classes
- PyQt5 - Hello World
- PyQt5 - What’s New
- PyQt5 - Introduction
- PyQt5 - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
PyQt5 - Using Qt Designer
The PyQt installer comes with a GUI builder tool called Qt Designer. Using its simple drag and drop interface, a GUI interface can be quickly built without having to write the code. It is however, not an IDE such as Visual Studio. Hence, Qt Designer does not have the facipty to debug and build the apppcation.
Start Qt Designer apppcation which is a part of development tools and installed in scripts folder of the virtual environment.
Start designing GUI interface by choosing File → New menu.
You can then drag and drop required widgets from the widget box on the left pane. You can also assign value to properties of widget laid on the form.
The designed form is saved as demo.ui. This ui file contains XML representation of widgets and their properties in the design. This design is translated into Python equivalent by using pyuic5 command pne utipty. This utipty is a wrapper for uic module of Qt toolkit. The usage of pyuic5 is as follows −
pyuic5 -x demo.ui -o demo.py
In the above command, -x switch adds a small amount of additional code to the generated Python script (from XML) so that it becomes a self-executable standalone apppcation.
if __name__ == "__main__": import sys app = QtGui.QApppcation(sys.argv) Dialog = QtGui.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_())
The resultant python script is executed to show the following dialog box −
python demo.py
The user can input data in input fields but cpcking on Add button will not generate any action as it is not associated with any function. Reacting to user-generated response is called as event handpng.
Advertisements