1. 程式人生 > 程式設計 >Pycharm安裝Qt Design快捷工具的詳細教程

Pycharm安裝Qt Design快捷工具的詳細教程

在使用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,如下圖所示,參考截圖設定

Qt Designer tools設定
PyUIC

設定好後就可以在Pycharm中看到該工具

在這裡插入圖片描述

接下來用Qt Design設計一款Gui介面,如下圖

Qt Design設計好的介面

在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,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,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,12))
    self.label_2.setObjectName("label_2")
    self.textEdit_2 = QtWidgets.QTextEdit(self.widget_query)
    self.textEdit_2.setGeometry(QtCore.QRect(300,30))
    self.textEdit_2.setObjectName("textEdit_2")
    self.label_3 = QtWidgets.QLabel(self.widget_query)
    self.label_3.setGeometry(QtCore.QRect(490,12))
    self.label_3.setObjectName("label_3")
    self.textEdit_3 = QtWidgets.QTextEdit(self.widget_query)
    self.textEdit_3.setGeometry(QtCore.QRect(560,30))
    self.textEdit_3.setObjectName("textEdit_3")
    self.toolButton = QtWidgets.QToolButton(self.widget_query)
    self.toolButton.setGeometry(QtCore.QRect(720,22,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,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,16))
    self.checkBox_2.setObjectName("checkBox_2")
    self.checkBox_3 = QtWidgets.QCheckBox(self.centralwidget)
    self.checkBox_3.setGeometry(QtCore.QRect(400,16))
    self.checkBox_3.setObjectName("checkBox_3")
    self.checkBox_4 = QtWidgets.QCheckBox(self.centralwidget)
    self.checkBox_4.setGeometry(QtCore.QRect(550,16))
    self.checkBox_4.setObjectName("checkBox_4")
    self.checkBox_5 = QtWidgets.QCheckBox(self.centralwidget)
    self.checkBox_5.setGeometry(QtCore.QRect(700,16))
    self.checkBox_5.setObjectName("checkBox_5")
    self.label_4 = QtWidgets.QLabel(self.centralwidget)
    self.label_4.setGeometry(QtCore.QRect(30,12))
    self.label_4.setObjectName("label_4")
    self.label_cepiaptype_2 = QtWidgets.QLabel(self.centralwidget)
    self.label_cepiaptype_2.setGeometry(QtCore.QRect(0,280,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()

設計好介面後接下來完成功能

12306站點抓取資料

到此這篇關於Pycharm安裝Qt Design快捷工具的文章就介紹到這了,更多相關Pycharm安裝Qt Design快捷工具內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!