pyqt QT designer made the About dialog box (software copyright notice)

First, the experimental environment

1.anaconda2 2.5.0 + python2.7

2.pyinstaller3.0

Second, the steps

2.1 Starting designer.exe

2.2 Click "File" -> "New" pop-up "New Window dialog", select the first option

2.3 Delete button at the bottom of OK Cancel

2.4 "Widget Box" in the toolbar and drag "Graphics View" control to the new dialog box above

2.5 Graphics View controls on right click and select "Change Style Sheet"

2.6 pop-up "Edit Style Sheet" dialog box, select "Add a resource" -> "border-image"

2.7 pop-up "Select Resources" dialog box, click "Edit Resource"

2.8 pop-up "Edit Resource" dialog box, click "Open Resource File"

2.9 pop-up "Import File" dialog box, select the file * .qrc own generation, click "Open." * .qrc file creation please refer to: https://www.cnblogs.com/hester/p/10471902.html

2.10 At this interface will return to step 2.8, click the "OK" button

2.11 You will be returned to step 2.7 interface, select the image you want, click "OK" button

2.12 You will be returned to step 2.6 interface, click the "OK" button

2.13 drag "Graphics View" control borders, image scaling to the appropriate size NOTE: XEL following pictures downloaded from the official website, please pay attention to copyright issues

2.14 "Widget Box" in the toolbar and drag "Label" control to the new dialog box above

2.15 Double-click controls, add text, the need for space row right click and select "Insert line breaks" (under state control text editor)

 2.16 Drag "Graphics" and "Label" control to the appropriate position, the final results are as follows

2.17 Click "File" -> "File Save As", a file named "about.ui"

2.18 generated code files

Open cmd window, switch to "about.ui" folder where the file, run the following command

pyuic5 -o about.py about.ui

2.19 “about.py”代码预览

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'about.ui'
#
# Created by: PyQt5 UI code generator 5.6
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(268, 136)
        Dialog.setModal(False)
        self.graphicsView = QtWidgets.QGraphicsView(Dialog)
        self.graphicsView.setGeometry(QtCore.QRect(10, 10, 241, 51))
        self.graphicsView.setStyleSheet("border-image: url(:/xel.png);")
        self.graphicsView.setObjectName("graphicsView")
        self.label = QtWidgets.QLabel(Dialog)
        self.label.setGeometry(QtCore.QRect(10, 70, 251, 61))
        self.label.setObjectName("label")

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
        self.label.setText(_translate("Dialog", "SmartBit端口占用者查看工具\n"
"Version 1.0.0\n"
"雄立科技 版权所有\n"
"Copyright (C) 2019 Xel.All Rights Reserved."))

import resource                #导入语句由工具自动生成,不建议修改位置

  

2.20 主窗口代码中调用about对话框,只给出导入语句和槽函数

from about import Ui_Dialog as Ui_About

def about(self):
    dialog = QDialog()
    dialog_help = Ui_About()
    dialog_help.setupUi(dialog)
    dialog.setFixedSize(dialog.width(), dialog.height())                #固定窗口大小,禁止缩放
    dialog.exec_()                                                      #配置为模态对话框

2.21 需要给对话框添加图标的,如上代码改写如下。QPixmap(":/xel_small.png")使用,请参考:https://www.cnblogs.com/hester/p/10471902.html

from about import Ui_Dialog as Ui_About

def about(self):
    icon = QtGui.QIcon()
    icon.addPixmap(QtGui.QPixmap(":/xel_small.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)

    dialog = QDialog()
    dialog_help = Ui_About()
    dialog_help.setupUi(dialog)
    dialog.setWindowIcon(icon)                                          #添加ico
    dialog.setFixedSize(dialog.width(), dialog.height())                #固定窗口大小,禁止缩放
    dialog.exec_()                                                      #配置为模态对话框

2.22 最终效果如下:

 

  

  

  

Guess you like

Origin www.cnblogs.com/hester/p/11229751.html