本来想直接继承QMessageBox
,但是继承之后窗口的大小、stylesheet
什么的都不太好搞定,于是重新做了一个,参考:QT自定义messagebox弹窗,使用PyQt
重写
布局:
自动生成代码:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(400, 165)
Dialog.setStyleSheet("QDialog {\n"
" background-color:white;\n"
"}\n"
"QPushButton {\n"
" border:2px solid rgb(0, 0, 127);\n"
" padding:5px;\n"
" border-radius:15px;\n"
" color:#000000;\n"
" background-color:transparent;\n"
" font-family: \'Microsoft YaHei Ui\';\n"
" font-size: 9pt;\n"
" font-weight: bold;\n"
"}\n"
"QPushButton:hover {\n"
" color:#0078d7;\n"
" background:rgb(255, 255, 255);\n"
" border:2px solid #0078d7;\n"
"}\n"
"QPushButton:pressed {\n"
" color:#000000;\n"
" background:#B8C6D1;\n"
"}\n"
"")
self.verticalLayout = QtWidgets.QVBoxLayout(Dialog)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
spacerItem = QtWidgets.QSpacerItem(15, 20, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.pbt_icon = QtWidgets.QPushButton(Dialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pbt_icon.sizePolicy().hasHeightForWidth())
self.pbt_icon.setSizePolicy(sizePolicy)
self.pbt_icon.setMinimumSize(QtCore.QSize(68, 64))
self.pbt_icon.setStyleSheet("background-color: transparent;\n"
"border:none;")
self.pbt_icon.setText("")
self.pbt_icon.setIconSize(QtCore.QSize(64, 64))
self.pbt_icon.setFlat(True)
self.pbt_icon.