最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

pycharm配置Qt?Designer工具的圖文教程

 更新時間:2023年06月05日 09:54:41   作者:是小峰呀  
本文主要介紹了pycharm配置Qt?Designer工具的圖文教程,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

之前一直使用QtCreator,在設(shè)計界面時非常方便,python早就集成了Qt模塊,在python中以pyQt的包存在,目前常用的是pyQt5,但是在pycharm中卻沒有找到像QtCreator那樣的編輯器,難道就只能通過代碼進行界面編輯嗎,那速度真是太慢了。不要慌,界面肯定是有的,而且非常方便,首先打開命令行安裝pyqt包,命令如下

pip install?PyQt5 -i https://pypi.doubanio.com/simple
pip install PyQt5-tools -i https://pypi.doubanio.com/simple
pip install paramiko -i https://pypi.doubanio.com/simple
pip install pyinstaller -i https://pypi.doubanio.com/simple

安裝完了之后,下面就是在pycharm中配置qt designer

打開File,選擇settings,然后找到External Tools,打開,第一次配置時界面如下

image.png

然后按照箭頭所示的操作進行

image.png

如果使用的是Anaconda,可以參考我的目錄進行配置,如果找不到designer.exe就在python的安裝目錄搜一下

image.png

然后是配置pyUIC,這個工具的作用是將UI文件轉(zhuǎn)換為.py文件

image.png

下面這個文件時打包用的,在命令行的用法是pyinstaller -F test.py

image.png

下面的工具是將ico圖標(biāo)放在qrc文件中,然后轉(zhuǎn)為py文件,用于生成打包后的圖標(biāo)

image.png

按照上面的步驟都安裝完成之后,可以在Tools中找到External Tools,然后里面就是我們剛剛創(chuàng)建的四個工具的快捷方式。

image.png

下面就是測試我們的設(shè)計工具,在項目文件中右鍵,會出來下面的菜單,在菜單中按照指示依次選擇

image.png

然后會打開如下的界面,第一次打開就是這個樣子,與qt Creator非常之像,簡直就是一個模子刻出來的,用法也基本相同,但是沒有右鍵控件轉(zhuǎn)到槽函數(shù)的功能,哈哈哈。

image.png

我們選擇widget,然后創(chuàng)建一個新的UI文件,然后選擇保存,保存的位置就是你的pycharm工程目錄

簡單的設(shè)計下面一個界面

image.png

然后關(guān)掉設(shè)計界面,回到pycharm,可以看到目錄中多了一個UI文件

image.png

在UI文件中我們右鍵,然后選擇External Tools

image.png

這時對應(yīng)UI的python代碼就已經(jīng)生成,可以看到目錄中多了一個與UI文件同名的py文件

image.png

內(nèi)容如下

# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'demo.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# 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
class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(1066, 796)
        self.horizontalLayoutWidget = QtWidgets.QWidget(Form)
        self.horizontalLayoutWidget.setGeometry(QtCore.QRect(10, 10, 1051, 80))
        self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
        self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.openimg = QtWidgets.QPushButton(self.horizontalLayoutWidget)
        self.openimg.setObjectName("openimg")
        self.horizontalLayout.addWidget(self.openimg)
        self.detect = QtWidgets.QPushButton(self.horizontalLayoutWidget)
        self.detect.setObjectName("detect")
        self.horizontalLayout.addWidget(self.detect)
        self.closewindow = QtWidgets.QPushButton(self.horizontalLayoutWidget)
        self.closewindow.setObjectName("closewindow")
        self.horizontalLayout.addWidget(self.closewindow)
        self.horizontalLayoutWidget_2 = QtWidgets.QWidget(Form)
        self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(10, 90, 1051, 701))
        self.horizontalLayoutWidget_2.setObjectName("horizontalLayoutWidget_2")
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_2)
        self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.label = QtWidgets.QLabel(self.horizontalLayoutWidget_2)
        self.label.setObjectName("label")
        self.horizontalLayout_2.addWidget(self.label)
        self.retranslateUi(Form)
        self.openimg.clicked.connect(Form.shouImg)
        self.detect.clicked.connect(Form.edgeDetect)
        self.closewindow.clicked.connect(Form.close)
        QtCore.QMetaObject.connectSlotsByName(Form)
    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.openimg.setText(_translate("Form", "打開圖片"))
        self.detect.setText(_translate("Form", "邊緣檢測"))
        self.closewindow.setText(_translate("Form", "關(guān)閉窗口"))
        self.label.setText(_translate("Form", "show Image"))

然后通過自建main函數(shù)進行調(diào)用,代碼如下

from demo import Ui_Form
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtWidgets import QApplication, QMainWindow, QCheckBox
from PyQt5.QtWidgets import QFileDialog
from PyQt5.QtCore import *
from PyQt5.QtCore import pyqtSlot
import sys
import os
import cv2
import numpy as np
from PyQt5.QtGui import *
class MainWindow(QMainWindow, Ui_Form):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent=parent)
        self.setupUi(self)
    # 打開圖片按鈕槽函數(shù)
    def shouImg(self):
        filePath = self.getFileDir()
        img = cv2.imread(filePath[0][0])
        img_dis = QImage(img, img.shape[1], img.shape[0], QImage.Format_RGB888)
        # 加載圖片,并設(shè)定圖片大小
        img_dis = QPixmap(img_dis).scaled(int(img.shape[1]), int(img.shape[0]))
        width = img_dis.width()  ##獲取圖片寬度
        height = img_dis.height()  ##獲取圖片高度
        if width / self.label.width() >= height / self.label.height():  ##比較圖片寬度與label寬度之比和圖片高度與label高度之比
            ratio = width / self.label.width()
        else:
            ratio = height / self.label.height()
        new_width = int(width / ratio)  ##定義新圖片的寬和高
        new_height = int(height / ratio)
        new_img = img_dis.scaled(new_width, new_height)  ##調(diào)整圖片尺寸
        # img_dis = QPixmap(img_dis).scaled(int(img.shape[1]), int(img.shape[0]))
        self.label.setPixmap(new_img)
    # 獲取文件地址函數(shù)
    def getFileDir(self):
        try:
            self.file_path = QFileDialog.getOpenFileNames(self, "select file", "./", "*.*")
        except Exception as e:
            print(e)
        return self.file_path
    def edgeDetect(self):
        # 自己發(fā)揮
        pass
if __name__ == "__main__":
    app = QApplication(sys.argv)
    w = MainWindow()
    w.show()
    sys.exit(app.exec_())

實驗結(jié)果如下

image.png

到此這篇關(guān)于pycharm配置Qt Designer工具的圖文教程的文章就介紹到這了,更多相關(guān)pycharm Qt Designer內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • PyTorch中關(guān)于tensor.repeat()的使用

    PyTorch中關(guān)于tensor.repeat()的使用

    這篇文章主要介紹了PyTorch中關(guān)于tensor.repeat()的使用,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • Python imageio讀取視頻并進行編解碼詳解

    Python imageio讀取視頻并進行編解碼詳解

    今天小編就為大家分享一篇Python imageio讀取視頻并進行編解碼詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-12-12
  • PyCharm 2021.2 (Professional)調(diào)試遠程服務(wù)器程序的操作技巧

    PyCharm 2021.2 (Professional)調(diào)試遠程服務(wù)器程序的操作技巧

    本文給大家分享用 PyCharm 2021 調(diào)試遠程服務(wù)器程序的過程,通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2021-08-08
  • 一篇文章徹底弄懂Python字符編碼

    一篇文章徹底弄懂Python字符編碼

    這篇文章主要介紹了一篇文章徹底弄懂Python字符編碼,各種常用的字符編碼的特點,并介紹了在python2.x中如何與編碼問題作戰(zhàn)?,下文詳細(xì)介紹需要的小伙伴可以參考一下
    2022-03-03
  • python docx 中文字體設(shè)置的操作方法

    python docx 中文字體設(shè)置的操作方法

    今天小編就為大家分享一篇python docx 中文字體設(shè)置的操作方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-05-05
  • 使用pyqt 實現(xiàn)重復(fù)打開多個相同界面

    使用pyqt 實現(xiàn)重復(fù)打開多個相同界面

    今天小編就為大家分享一篇使用pyqt 實現(xiàn)重復(fù)打開多個相同界面,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-12-12
  • 關(guān)于python常見異常以及處理方法

    關(guān)于python常見異常以及處理方法

    這篇文章主要介紹了關(guān)于python常見異常以及處理方法,python用異常對象(exception object)來表示異常情況。遇到錯誤后,會引發(fā)異常,需要的朋友可以參考下
    2023-04-04
  • pandas groupby()的使用小結(jié)

    pandas groupby()的使用小結(jié)

    在數(shù)據(jù)分析中,經(jīng)常會用到分組,可用函數(shù)pandas中的groupby(),本文就來介紹一下pandas groupby()的使用小結(jié),具有一定的參考價值,感興趣的可以了解一下
    2023-11-11
  • 基于python實現(xiàn)KNN分類算法

    基于python實現(xiàn)KNN分類算法

    這篇文章主要為大家詳細(xì)介紹了基于python實現(xiàn)KNN分類算法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-01-01
  • Python可視化學(xué)習(xí)之matplotlib內(nèi)置單顏色

    Python可視化學(xué)習(xí)之matplotlib內(nèi)置單顏色

    這篇文章主要為大家介紹了Python matplotlib中支持的顏色格式及內(nèi)置的單顏色色號的匯總,文中的示例代碼講解詳細(xì),需要的可以參考一下
    2022-02-02

最新評論

隆尧县| 大石桥市| 康保县| 襄垣县| 枣阳市| 红桥区| 宁武县| 宁武县| 吴忠市| 栾城县| 辽阳市| 马公市| 栾城县| 垦利县| 开平市| 巢湖市| 平陆县| 荥阳市| 得荣县| 关岭| 沂源县| 新巴尔虎右旗| 将乐县| 佛教| 衡阳县| 宝应县| 承德市| 肇源县| 无极县| 元朗区| 会昌县| 广州市| 汤阴县| 泗阳县| 于都县| 昌邑市| 安仁县| 太湖县| 江阴市| 鹤壁市| 抚松县|