design requires a separate installation. Directly pip3 install PyQt5-tools you will be prompted to find the installation files.
https://github.com/altendky/pyqt5-tools/releases/tag/v5.7.dev1
pip install PyQt5-tools -i http://pypi.douban.com/simple --trusted-host=pypi.douban.com
Qt Designer Introduction
PyQt prepared UI interface may be implemented by the code directly, can also be done by Qt Designer. Qt Designer is designed to meet the MVC architecture, which realizes the separation of view and logic, enabling easy development. Qt Designer mode of operation is very flexible in its place controls by drag and drop effects can view the controls at any time. Qt Designer generated .ui file (XML format file substantially) may also be converted into files .py pyuic5 tool.
Qt Designer with PyQt5-tools installed with the package, its installation path "Python installation path \ Lib \ site-packages \ pyqt5 -tools".
To start Qt Designer directly to the above-mentioned folder, double-click to open designer.exe Qt Designer; or environment variable added to the route, the designer open command input line; PyCharm or in the external tool that is configured to open.
Below PyCharm example, about PyCharm Qt Designer in the configuration.
PyCharm in PyQt5 configuration tool
Open PyCharm, select Settings -> Tools -> External Tools, click on the upper left corner of the green plus sign.
Name fill QtDesigner (facilitate subsequent use, the name does not matter). Program selection PyQt5-tools following our installation designer.exe. Working directory select our working directory. Then click OK, then added QtDesigner as PyCharm external tools.
Then add PyUIC (UI conversion tool), PyUIC the Program for the Python.exe, in the installation directory of the Python Scripts directory, Working directory empathy to our working directory, Arguments then fill in the following code:
-m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py
Finally add pyrcc for PyQt5 resource file transcoding. DETAILED same configuration with the foregoing, Arguments fill:
$FileName$ -o $FileNameWithoutExtension$_rc.py
Before exiting, click Apply to save the configuration. After configuration is complete, PyCharm will join three tools.
Click QtDesigner QtDesigner interface opens.
About Qt Designer interface
Just open Qt Designer, pop-up windows as shown in FIG.
Create a new Form gives five templates, which most commonly Widget and Main Window. Here we choose to create a Main Window.
Leftmost menu screen above is Widget Box, Widget Box Widget contains all the components PyQt5, we can drag from the left side of the assembly, such as the Widget Box Button, View, and the like to the intermediate Input window.
Click Form -> Preview (shortcut key is Ctrl + R) you can preview we designed interface can also be used to select the Preview In the preview at the appropriate topic style.
We drag a Label and Button to enter the main window (Main Window).
At this time, the object can be seen (label and pushButton) Qt classes and their corresponding main window has been placed in the upper right corner of the Object Inspector (Object Viewer).
Label with an example, when we click the Main Window in the label or the label selected in the Object Inspector, to see an area on the right side of --Property Editor (Attribute Editor).
Which mainly comprises the following attributes:
name | meaning |
---|---|
objectName | Controls object name |
geometry | Width and height corresponding to the coordinates |
sizePolicy | Controls the size of the strategy |
minimumSize | The minimum width and height |
maximumSize | The maximum width and height |
font | Fonts |
cursor | cursor |
... | ... |
PS: After the value is set to the same minimumSize and maximumSize, the window size is fixed.
The lower right corner of the part is the Resource Browser (Explorer), Explorer can be added accordingly as picture material, such as a Label or Button control's background pictures.
Qt Designer's UI files
Qt Designer design files saved to .ui format.
By saving and use Notepad to open the software, we can see the contents of .ui file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <class>MainWindow</class> <widget class="QMainWindow" name="MainWindow"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>800</width> <height>600</height> </rect> </property> <property name="windowTitle"> <string>MainWindow</string> </property> <widget class="QWidget" name="centralwidget"> <widget class="QLabel" name="label"> <property name="geometry"> <rect> <x>240</x> <y>80</y> <width>72</width> <height>15</height> </rect> </property> <property name="text"> <string>TextLabel</string> </property> </widget> <widget class="QPushButton" name="pushButton"> <property name="geometry"> <rect> <x>240