119 lines
3.8 KiB
Python
119 lines
3.8 KiB
Python
from PyQt5.QtWidgets import *
|
||
from PyQt5.QtCore import Qt
|
||
|
||
|
||
class PopDialogMessage:
|
||
|
||
def __init__(self, parent):
|
||
super().__init__()
|
||
self.cancel_action = None
|
||
self.commit_action = None
|
||
self.parent = parent
|
||
|
||
desktop = QDesktopWidget()
|
||
self.screenRect = desktop.availableGeometry()
|
||
self.dialog = QDialog(
|
||
flags=Qt.CustomizeWindowHint | Qt.WindowCloseButtonHint | Qt.WindowStaysOnTopHint
|
||
) # 设置无图标和标题
|
||
self.dialog.setStyleSheet("background-color:#ffffff;")
|
||
self.dialog.setContentsMargins(0, 0, 0, 0)
|
||
self.dialog.setFixedSize(int(self.screenRect.width() * 0.35),
|
||
int(self.screenRect.height() * 0.35)) # 设置对话框的宽度为屏幕的35%,高度为屏幕的70%
|
||
|
||
self.cancel_btn = self._init_cancel_button()
|
||
self.commit_btn = self._init_commit_button()
|
||
|
||
self.cancel_btn.clicked.connect(self.cancel_button_action)
|
||
self.commit_btn.clicked.connect(self.commit_button_action)
|
||
|
||
self.title_label = QLabel()
|
||
self.title_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
|
||
self.title_label.setWordWrap(True)
|
||
self.title_label.setStyleSheet(
|
||
"font: 30px \"Microsoft YaHei UI\";"
|
||
"letter-spacing: 4px;"
|
||
"margin-left: 6px;"
|
||
"margin-right: 6px;"
|
||
)
|
||
|
||
self.btn_layout = QHBoxLayout()
|
||
self.btn_layout.addWidget(self.cancel_btn, 50)
|
||
self.btn_layout.addWidget(self.commit_btn, 50)
|
||
# 总布局
|
||
self.main_layout = QVBoxLayout()
|
||
self.main_layout.addWidget(self.title_label, 50)
|
||
self.main_layout.addLayout(self.btn_layout, 50)
|
||
|
||
self.dialog.setLayout(self.main_layout)
|
||
|
||
# 添加遮罩层,设置parent,确保遮罩层在父页面中显示
|
||
self.overlay = QWidget(self.parent)
|
||
self.overlay.setStyleSheet("background-color: rgba(0, 0, 0, 0.5);")
|
||
self.overlay.resize(self.screenRect.width(), self.screenRect.height())
|
||
self.overlay.hide()
|
||
|
||
def show(self, title_label):
|
||
self.overlay.show()
|
||
self.title_label.setText(title_label)
|
||
self.dialog.show()
|
||
|
||
def hide(self):
|
||
self.dialog.hide()
|
||
self.overlay.hide()
|
||
|
||
# 取消按钮响应事件
|
||
def cancel_button_action(self):
|
||
self.dialog.hide()
|
||
self.overlay.hide()
|
||
if self.cancel_action:
|
||
self.cancel_action()
|
||
|
||
# 确认按钮响应事件
|
||
def commit_button_action(self):
|
||
self.dialog.hide()
|
||
self.overlay.hide()
|
||
# 调用链接函数
|
||
if self.commit_action:
|
||
self.commit_action()
|
||
|
||
def connect(self, func):
|
||
self.commit_action = func
|
||
|
||
def cancel_connect(self, func):
|
||
self.cancel_action = func
|
||
|
||
# 初始化取消按钮
|
||
@staticmethod
|
||
def _init_cancel_button():
|
||
cancel_btn = QPushButton("取消")
|
||
cancel_btn.setStyleSheet(
|
||
"border: 1px solid #222222;"
|
||
"color: #222222;"
|
||
"padding-top: 30px;"
|
||
"padding-bottom: 30px;"
|
||
"margin-left: 20px;"
|
||
"margin-right: 20px;"
|
||
"margin-bottom: 20px;"
|
||
"border-radius: 4px;"
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
)
|
||
return cancel_btn
|
||
|
||
# 初始化确认按钮
|
||
@staticmethod
|
||
def _init_commit_button():
|
||
commit_btn = QPushButton("确定")
|
||
commit_btn.setStyleSheet(
|
||
"border: 1px solid #409eff;"
|
||
"color: #ffffff;"
|
||
"padding-top: 30px;"
|
||
"padding-bottom: 30px;"
|
||
"margin-left: 20px;"
|
||
"margin-right: 20px;"
|
||
"margin-bottom: 20px;"
|
||
"border-radius: 4px;"
|
||
"font: 24px \"Microsoft YaHei UI\";"
|
||
"background-color: #409eff;"
|
||
)
|
||
return commit_btn
|