Configure Pyqt5 tools in Pycharm (2023 new version tutorial)

1. Install related modules

Install the three basic packages of pyqt5, pyqt5designer, and pyqt5-tools. The commands are as follows:

pip install pyqt5
pip install pyqt5-tools
pip install pyqt5designer

2. Add external tools in Pycharm

a. QtDesigner tool (for writing .ui files)

In the Pycharm software, click [File] → [Settings] → [Tools] → [External Tools] to reach this interface:

①Click the [+] sign, and the window ② will pop up

1. After clicking the plus sign, fill in the following contents in [Name], [Program], and [Working Directory]:

2. Name (you can write whatever you want, for easy identification, fill in Qt Designer)

Qt Designer

3. Program (that is, the place where QtDesigner.exe is installed, when you install pyqt5designer using pip in the cmd window, it has already been installed in the directory where python is installed. The following is my python installation directory and the default startup location of QtDesigner)

D:\Program Files\Python38\Scripts\designer.exe

4. Working directory (indicates where to enable this function, just fill in the constants below)

$ProjectFileDir$

5. Click【OK】【OK】

Then you can find the tools we added manually in the External Tools directory after right-clicking the project file.

b. PyUIC tool (for converting .ui files to .py files)

The method is similar to the Qt Designer tool:

1. After clicking the plus sign, fill in the following contents in [Name], [Program], [Actual Parameter] , and [Working Directory]:

2. Name (you can write whatever you want: I am used to writing Ui to py, and textbooks generally write PyUIC)

Ui to py

3. Program (in the same directory as the above Qt Designer, there is pyuic5.exe, which is it)

D:\Program Files\Python38\Scripts\pyuic5.exe

4. Actual parameters (you need to input parameters when executing pyuic.exe, just fill in the following command)

-o $FileNameWithoutExtension$.py $FileName$

5. Working directory (indicates where to enable this function, just fill in the constants below)

$FileDir$

c. PyRCC tool (for converting .qrc files to .py files)

 The method is similar to the Qt Designer tool:

1. After clicking the plus sign, fill in the following contents in [Name], [Program], [Actual Parameter] , and [Working Directory]:

2. Name (you can write whatever you want: I am used to writing Qrc to py)

Qrc to py

3. Program (in the same directory as the above-mentioned Qt Designer, there is a pyrcc5.exe, which is it)

D:\Program Files\Python38\Scripts\pyrcc5.exe

4. Actual parameters (you need to enter parameters when executing pyrcc.exe, just fill in the following command, pay attention to one word can not be wrong )

$FileName$ -o $FileNameWithoutExtension$_rc.py

5. Working directory (indicates where to enable this function, just fill in the constants below)

$FileDir$

 3. The final effect

 Right-click on the project name or file name to display the following three tools.

おすすめ

転載: blog.csdn.net/yuanchenglei/article/details/124936528
おすすめ