Pycharm安装Qt Design快捷工具的详细教程
(编辑:jimmy 日期: 2024/11/2 浏览:3 次 )
在使用Python开发Gui程序可以使用Qt Design工具进行界面设计,下面记录在Pycharm中设置Qt Design快捷工具和如何把Qt Design中图形化的ui界面文件转化成py文件
先记录好需要填写的内容
1、Qt_Designer 快捷工具名称
2、(填写Qt安装的路径 designer.exe)
3、$ProjectFileDir$
1、PyUIC 快捷工具名称
2、python的安装目录
3、-m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py Ui文件转py文件
4、$FileDir$ 文件目录
步骤一:pycharm中 File>Settings>Tools>External Tools,如下图所示,参考截图设置
设置好后就可以在Pycharm中看到该工具
接下来用Qt Design设计一款Gui界面,如下图
在Qt Designer可视化界面设计好后导出该文件,最后用PyUIC工具转化成python代码
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'chepiao.ui' # # Created by: PyQt5 UI code generator 5.15.1 # # WARNING: Any manual changes made to this file will be lost when pyuic5 is # run again. Do not edit this file unless you know what you are doing. from PyQt5 import QtCore, QtGui, QtWidgets import sys from PyQt5.QtGui import QPalette,QPixmap,QColor class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(960, 786) MainWindow.setMinimumSize(QtCore.QSize(960, 786)) MainWindow.setMaximumSize(QtCore.QSize(960, 786)) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.label_title_img = QtWidgets.QLabel(self.centralwidget) self.label_title_img.setGeometry(QtCore.QRect(0, 0, 960, 141)) title_img = QPixmap('png/bg1.png') # 打开顶部位图 self.label_title_img.setPixmap(title_img) #设置调色板 self.label_title_img.setText("") self.label_title_img.setObjectName("label_title_img") self.widget_query = QtWidgets.QWidget(self.centralwidget) self.widget_query.setGeometry(QtCore.QRect(0, 141, 960, 80)) #self.widget_query.setStyleSheet("background-image: url(:/png/bg3.png);") self.widget_query.setAutoFillBackground(True) #开启自动填充背景 palette = QPalette() #调色板类 palette.setBrush(QPalette.Background,QtGui.QBrush(QtGui.QPixmap('png/bg2.png'))) self.widget_query.setPalette(palette) self.widget_query.setObjectName("widget_query") self.label = QtWidgets.QLabel(self.widget_query) self.label.setGeometry(QtCore.QRect(30, 30, 54, 12)) self.label.setObjectName("label") self.textEdit = QtWidgets.QTextEdit(self.widget_query) self.textEdit.setGeometry(QtCore.QRect(80, 20, 110, 30)) self.textEdit.setObjectName("textEdit") self.label_2 = QtWidgets.QLabel(self.widget_query) self.label_2.setGeometry(QtCore.QRect(240, 30, 54, 12)) self.label_2.setObjectName("label_2") self.textEdit_2 = QtWidgets.QTextEdit(self.widget_query) self.textEdit_2.setGeometry(QtCore.QRect(300, 20, 110, 30)) self.textEdit_2.setObjectName("textEdit_2") self.label_3 = QtWidgets.QLabel(self.widget_query) self.label_3.setGeometry(QtCore.QRect(490, 30, 54, 12)) self.label_3.setObjectName("label_3") self.textEdit_3 = QtWidgets.QTextEdit(self.widget_query) self.textEdit_3.setGeometry(QtCore.QRect(560, 20, 110, 30)) self.textEdit_3.setObjectName("textEdit_3") self.toolButton = QtWidgets.QToolButton(self.widget_query) self.toolButton.setGeometry(QtCore.QRect(720, 22, 54, 26)) self.toolButton.setObjectName("toolButton") self.textEdit_2.raise_() self.label.raise_() self.label_2.raise_() self.label_3.raise_() self.textEdit.raise_() self.textEdit_3.raise_() self.toolButton.raise_() self.label_cepiaptype = QtWidgets.QLabel(self.centralwidget) self.label_cepiaptype.setGeometry(QtCore.QRect(0, 220, 960, 60)) #self.label_cepiaptype.setStyleSheet("background-image: url(:/png/bg3.png);") self.label_cepiaptype.setAutoFillBackground(True) # 开启自动填充背景 palette = QPalette() # 调色板类 palette.setBrush(QPalette.Background, QtGui.QBrush(QtGui.QPixmap('png/bg3.png'))) self.label_cepiaptype.setPalette(palette) self.label_cepiaptype.setText("") self.label_cepiaptype.setObjectName("label_cepiaptype") self.checkBox = QtWidgets.QCheckBox(self.centralwidget) self.checkBox.setGeometry(QtCore.QRect(100, 240, 71, 16)) self.checkBox.setObjectName("checkBox") self.checkBox_2 = QtWidgets.QCheckBox(self.centralwidget) self.checkBox_2.setGeometry(QtCore.QRect(250, 240, 71, 16)) self.checkBox_2.setObjectName("checkBox_2") self.checkBox_3 = QtWidgets.QCheckBox(self.centralwidget) self.checkBox_3.setGeometry(QtCore.QRect(400, 240, 71, 16)) self.checkBox_3.setObjectName("checkBox_3") self.checkBox_4 = QtWidgets.QCheckBox(self.centralwidget) self.checkBox_4.setGeometry(QtCore.QRect(550, 240, 71, 16)) self.checkBox_4.setObjectName("checkBox_4") self.checkBox_5 = QtWidgets.QCheckBox(self.centralwidget) self.checkBox_5.setGeometry(QtCore.QRect(700, 240, 71, 16)) self.checkBox_5.setObjectName("checkBox_5") self.label_4 = QtWidgets.QLabel(self.centralwidget) self.label_4.setGeometry(QtCore.QRect(30, 240, 54, 12)) self.label_4.setObjectName("label_4") self.label_cepiaptype_2 = QtWidgets.QLabel(self.centralwidget) self.label_cepiaptype_2.setGeometry(QtCore.QRect(0, 280, 960, 60)) #self.label_cepiaptype_2.setStyleSheet("background-image: url(:/png/bg4.png);") self.label_cepiaptype_2.setAutoFillBackground(True) # 开启自动填充背景 palette = QPalette() # 调色板类 palette.setBrush(QPalette.Background, QtGui.QBrush(QtGui.QPixmap('png/bg4.png'))) self.label_cepiaptype_2.setPalette(palette) self.label_cepiaptype_2.setText("") self.label_cepiaptype_2.setObjectName("label_cepiaptype_2") self.textBrowser = QtWidgets.QTextBrowser(self.centralwidget) self.textBrowser.setGeometry(QtCore.QRect(0, 340, 970, 450)) self.textBrowser.setObjectName("textBrowser") self.widget_query.raise_() self.label_cepiaptype.raise_() self.label_title_img.raise_() self.checkBox.raise_() self.checkBox_2.raise_() self.checkBox_3.raise_() self.checkBox_4.raise_() self.checkBox_5.raise_() self.label_4.raise_() self.label_cepiaptype_2.raise_() self.textBrowser.raise_() MainWindow.setCentralWidget(self.centralwidget) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "快手爬票")) self.label.setText(_translate("MainWindow", "出发地")) self.label_2.setText(_translate("MainWindow", "目的地")) self.label_3.setText(_translate("MainWindow", "出发日期")) self.toolButton.setText(_translate("MainWindow", "查询")) self.checkBox.setText(_translate("MainWindow", "GC-高铁")) self.checkBox_2.setText(_translate("MainWindow", "D-动车")) self.checkBox_3.setText(_translate("MainWindow", "Z-直达")) self.checkBox_4.setText(_translate("MainWindow", "T-特快")) self.checkBox_5.setText(_translate("MainWindow", "K-快速")) self.label_4.setText(_translate("MainWindow", "车次类型:")) def show_MainWindow(): app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec_()) show_MainWindow()
设计好界面后接下来完成功能
下一篇:python 使用tkinter+you-get实现视频下载器