PyQt5 + Qt Designer配置指令

Ubuntu + PyCharm + Qt Designer 全套配置指令

一、安装依赖

更新软件源

sudo apt update

安装 Qt5、Qt Designer、PyQt5 工具

sudo apt install qt5-default qttools5-dev-tools qtcreator pyqt5-dev-tools -y

确认安装成功

qtdesigner --version

pyuic5 --version

pyrcc5 --version

Qt Designer 可执行文件路径:

/usr/bin/designer


二、PyCharm 配置 External Tools

进入 File → Settings → Tools → External Tools,分别添加以下三个工具。

1. Qt Designer

·

Name: Qt Designer

·

·

Program: /usr/bin/designer

·

·

Arguments: FileNameFileNameFileName

·

·

Working directory: FileDirFileDirFileDir

·


2. PyUIC5(UI 转 Python)

·

Name: PyUIC5

·

·

Program: pyuic5

·

·

Arguments:

·

-o FileNameWithoutExtensionFileNameWithoutExtensionFileNameWithoutExtension_ui.py FileNameFileNameFileName

·

·

Working directory: FileDirFileDirFileDir

·

(这样 mainwindow.ui → mainwindow_ui.py)


3. Pyrcc5(资源文件 QRC 转 Python)

Name: Pyrcc5

Program: pyrcc5

Arguments:

-o FileNameWithoutExtensionFileNameWithoutExtensionFileNameWithoutExtension_rc.py FileNameFileNameFileName

Working directory: FileDirFileDirFileDir

(这样 resources.qrc → resources_rc.py)


三、项目使用流程

在 PyCharm 里新建 .ui 文件,用 External Tools → Qt Designer 打开设计界面。

设计好界面后,右键 .ui 文件 → External Tools → PyUIC5,生成 xxx_ui.py。

如果有 .qrc 资源文件,右键 .qrc → External Tools → Pyrcc5,生成 xxx_rc.py。

在 Python 脚本中调用生成的类,例如:

import sys

from PyQt5.QtWidgets import QApplication, QMainWindow

from mainwindow_ui import Ui_MainWindow # UI 文件生成的类

class MyWindow(QMainWindow, Ui_MainWindow):

def init(self):

super().init()

self.setupUi(self)

self.pushButton.clicked.connect(self.say_hello)

def say_hello(self):

self.label.setText("Hello, PyQt5!")

if name == "main":

app = QApplication(sys.argv)

window = MyWindow()

window.show()

sys.exit(app.exec_())


四、验证运行

python3 main.py

如果窗口能弹出,并且点击按钮能响应,说明环境配置完成 ✅。


相关推荐
xcyxiner1 天前
DicomViewer (目录调整) 2
qt
xcyxiner1 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
LDR0063 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术3 天前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript
码云数智-园园3 天前
C++20 Modules 模块详解
java·开发语言·spring
swordbob3 天前
NIO的channel中什么是 fd(File Descriptor,文件描述符)
java·开发语言·nio
源分享3 天前
Java线程同步的多种实现方法(非常详细)
java·开发语言·jvm
Luminous.3 天前
C语言--day30
c语言·开发语言
何以解忧,唯有..3 天前
Go语言循环语句详解:for、range与循环控制
开发语言·算法·golang
謓泽3 天前
C语言不是语法,是通往机器的地图。
c语言·开发语言