PyQt - cheeseBG/EmergencyResponseSystem GitHub Wiki
PyQt
PyQt refers to a framework
that allows you to create GUI programs by connecting Python code to Qt's layout.
PyQt started by making a tool that converts Qt, the Cross Platform GUI Framework of C++, into a Python module at Riverbank Computing in the UK.
Currently, PyQt4
version and PyQt5
version are mainly used.
Qt designer
Appendix: https://wikidocs.net/35479
Qt Designer is an editor
that allows you to easily edit the program layout when programming GUI using PyQt.
There are many ways to install Qt Designer, but we will look at the easiest way to use Anaconda
.
- Window
Start Menu
Run ‘Anaconda Prompt’
Enter ‘designer’
Qt Designer works!
- Mac
Application
Find ‘Anaconda Navigator’
Right-Click
Choose ‘Show Original’
Qt Designer works!
- Simple Feature Explanation
(1) Dialog Window: Dialog Window is the place that will actually be the screen of the program. Widgets are placed on this screen to compose the program screen.
(2) Widget Box: Widget Box is a screen where widgets (objects such as buttons that function in a program) are collected. From here, you can add widgets by dragging the widgets you want to the Dialog Window. You can use various Buttons/Layouts/Display Widgets etc.
(3) Object Inspector: The Object Inspector is where you control the dependencies of widgets. Here, you can do things like putting widgets inside a container.
(4) Property Editor: Property Editor is a screen to control the properties of widgets. Also include size/font/background/title etc of widgets.
Saving the UI and connecting it to the Python code?
Appendix: https://wikidocs.net/5226
If we have created UIs by placing widgets, we should know how to save this UI and connect it with Python code.
- Saving the UI
You can save by pressing the save button (Control + S / Command + S).
The name of the UI file can be any name you like.
One thing to keep in mind when saving the UI file is to place it in the same directory as your Python code so that it is easy to import from your Python code.
- Connecting it to the Python code
Converting UI files to Python code is more convenient to revise.
Move ui file to a directory named C:\Anaconda3\Lib\site-packages\PyQt5\uic.
Select the uic directory in the C:\Anaconda3\Lib\site-packages\PyQt5 directory, hold down the Shift key and right-click. Select 'Open command window here'.
Enter ‘python -m PyQt5.uic.pyuic -x [your ui name].ui -o [your python name].py’
If conversion is performed normally without error, [your python name].py file is created in C:\Anaconda3\Lib\site-packages\PyQt5\uic directory. You can use ui file as a python code with simply import ui file.