提交 8d7ae87b 编写于 作者: 之一Yo's avatar 之一Yo

添加带遮罩的圆角消息框

上级 5aa049ee
...@@ -3,7 +3,7 @@ import sys ...@@ -3,7 +3,7 @@ import sys
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from qfluentwidgets import MessageDialog from qfluentwidgets import MessageDialog, MessageBox
class Window(QWidget): class Window(QWidget):
...@@ -20,7 +20,8 @@ class Window(QWidget): ...@@ -20,7 +20,8 @@ class Window(QWidget):
def showDialog(self): def showDialog(self):
title = 'Are you sure you want to delete the folder?' title = 'Are you sure you want to delete the folder?'
content = """If you delete the "Music" folder from the list, the folder will no longer appear in the list, but will not be deleted.""" content = """If you delete the "Music" folder from the list, the folder will no longer appear in the list, but will not be deleted."""
w = MessageDialog(title, content, self) # w = MessageDialog(title, content, self) # Win10 style message box
w = MessageBox(title, content, self)
if w.exec(): if w.exec():
print('Yes button is pressed') print('Yes button is pressed')
else: else:
......
...@@ -10,7 +10,7 @@ online at https://pyqt-fluent-widgets.readthedocs.io. ...@@ -10,7 +10,7 @@ online at https://pyqt-fluent-widgets.readthedocs.io.
:license: MIT, see LICENSE for more details. :license: MIT, see LICENSE for more details.
""" """
__version__ = "0.2.7" __version__ = "0.2.8"
from .components import * from .components import *
from .common import * from .common import *
......
...@@ -10,6 +10,17 @@ QDialog { ...@@ -10,6 +10,17 @@ QDialog {
border-bottom: none; border-bottom: none;
} }
MessageBox #buttonGroup {
border-bottom-left-radius: 8px;
border-bottom-right-radius: 8px;
}
#centerWidget {
border: 1px solid rgb(58, 58, 58);
border-radius: 8px;
background-color: rgb(43, 43, 43);
}
QLabel { QLabel {
background-color: transparent; background-color: transparent;
color: white; color: white;
......
...@@ -10,6 +10,17 @@ QDialog { ...@@ -10,6 +10,17 @@ QDialog {
border-bottom: none; border-bottom: none;
} }
MessageBox #buttonGroup {
border-bottom-left-radius: 8px;
border-bottom-right-radius: 8px;
}
#centerWidget {
border: 1px solid rgb(144, 144, 142);
border-radius: 8px;
background-color: white;
}
QLabel { QLabel {
background-color: transparent; background-color: transparent;
} }
......
此差异已折叠。
from .color_dialog import ColorDialog from .color_dialog import ColorDialog
from .dialog import Dialog from .dialog import Dialog, MessageBox
from .folder_list_dialog import FolderListDialog from .folder_list_dialog import FolderListDialog
from .message_dialog import MessageDialog from .message_dialog import MessageDialog
\ No newline at end of file
# coding:utf-8 # coding:utf-8
from PyQt5.QtCore import Qt, pyqtSignal from PyQt5.QtCore import Qt, pyqtSignal, QObject
from PyQt5.QtWidgets import QLabel, QPushButton, QFrame, QVBoxLayout, QHBoxLayout from PyQt5.QtGui import QColor
from PyQt5.QtWidgets import QLabel, QPushButton, QFrame, QVBoxLayout, QHBoxLayout, QSizePolicy
from qframelesswindow import FramelessDialog from qframelesswindow import FramelessDialog
from ...common.auto_wrap import TextWrap from ...common.auto_wrap import TextWrap
from ...common.style_sheet import setStyleSheet from ...common.style_sheet import setStyleSheet
from .mask_dialog_base import MaskDialogBase
class Dialog(FramelessDialog):
""" Dialog box """ class Ui_MessageBox(QObject):
""" Ui of message box """
yesSignal = pyqtSignal() yesSignal = pyqtSignal()
cancelSignal = pyqtSignal() cancelSignal = pyqtSignal()
def __init__(self, title: str, content: str, parent=None): def _setUpUi(self, title, content, parent):
super().__init__(parent)
self.resize(240, 192)
self.titleBar.hide()
self.content = content self.content = content
self.titleLabel = QLabel(title, self) self.titleLabel = QLabel(title, parent)
self.contentLabel = QLabel(content, self) self.contentLabel = QLabel(content, parent)
self.windowTitleLabel = QLabel(title, self)
self.buttonGroup = QFrame(self) self.buttonGroup = QFrame(parent)
self.yesButton = QPushButton(self.tr('OK'), self.buttonGroup) self.yesButton = QPushButton(self.tr('OK'), self.buttonGroup)
self.cancelButton = QPushButton(self.tr('Cancel'), self.buttonGroup) self.cancelButton = QPushButton(self.tr('Cancel'), self.buttonGroup)
self.vBoxLayout = QVBoxLayout(self) self.vBoxLayout = QVBoxLayout(parent)
self.textLayout = QVBoxLayout() self.textLayout = QVBoxLayout()
self.buttonLayout = QHBoxLayout(self.buttonGroup) self.buttonLayout = QHBoxLayout(self.buttonGroup)
...@@ -40,7 +38,6 @@ class Dialog(FramelessDialog): ...@@ -40,7 +38,6 @@ class Dialog(FramelessDialog):
self.yesButton.setFocus() self.yesButton.setFocus()
self.buttonGroup.setFixedHeight(81) self.buttonGroup.setFixedHeight(81)
self.contentLabel.setText(TextWrap.wrap(self.content, 100, False)[0]) self.contentLabel.setText(TextWrap.wrap(self.content, 100, False)[0])
self.setResizeEnabled(False)
self.yesButton.clicked.connect(self.__onYesButtonClicked) self.yesButton.clicked.connect(self.__onYesButtonClicked)
self.cancelButton.clicked.connect(self.__onCancelButtonClicked) self.cancelButton.clicked.connect(self.__onCancelButtonClicked)
...@@ -48,9 +45,9 @@ class Dialog(FramelessDialog): ...@@ -48,9 +45,9 @@ class Dialog(FramelessDialog):
def __initLayout(self): def __initLayout(self):
self.vBoxLayout.setSpacing(0) self.vBoxLayout.setSpacing(0)
self.vBoxLayout.setContentsMargins(0, 0, 0, 0) self.vBoxLayout.setContentsMargins(0, 0, 0, 0)
self.vBoxLayout.addWidget(self.windowTitleLabel, 0, Qt.AlignTop)
self.vBoxLayout.addLayout(self.textLayout, 1) self.vBoxLayout.addLayout(self.textLayout, 1)
self.vBoxLayout.addWidget(self.buttonGroup, 0, Qt.AlignBottom) self.vBoxLayout.addWidget(self.buttonGroup, 0, Qt.AlignBottom)
self.vBoxLayout.setSizeConstraint(QVBoxLayout.SetMinimumSize)
self.textLayout.setSpacing(12) self.textLayout.setSpacing(12)
self.textLayout.setContentsMargins(24, 24, 24, 24) self.textLayout.setContentsMargins(24, 24, 24, 24)
...@@ -76,9 +73,48 @@ class Dialog(FramelessDialog): ...@@ -76,9 +73,48 @@ class Dialog(FramelessDialog):
self.contentLabel.setObjectName("contentLabel") self.contentLabel.setObjectName("contentLabel")
self.yesButton.setObjectName('yesButton') self.yesButton.setObjectName('yesButton')
self.buttonGroup.setObjectName('buttonGroup') self.buttonGroup.setObjectName('buttonGroup')
self.windowTitleLabel.setObjectName('windowTitleLabel')
setStyleSheet(self, 'dialog') setStyleSheet(self, 'dialog')
self.yesButton.adjustSize() self.yesButton.adjustSize()
self.cancelButton.adjustSize() self.cancelButton.adjustSize()
class Dialog(FramelessDialog, Ui_MessageBox):
""" Dialog box """
yesSignal = pyqtSignal()
cancelSignal = pyqtSignal()
def __init__(self, title: str, content: str, parent=None):
super().__init__(parent=parent)
self._setUpUi(title, content, self)
self.windowTitleLabel = QLabel(title, self)
self.setResizeEnabled(False)
self.resize(240, 192)
self.titleBar.hide()
self.vBoxLayout.insertWidget(0, self.windowTitleLabel, 0, Qt.AlignTop)
self.windowTitleLabel.setObjectName('windowTitleLabel')
setStyleSheet(self, 'dialog')
class MessageBox(MaskDialogBase, Ui_MessageBox):
""" Message box """
yesSignal = pyqtSignal()
cancelSignal = pyqtSignal()
def __init__(self, title: str, content: str, parent=None):
super().__init__(parent=parent)
self._setUpUi(title, content, self.widget)
self.setShadowEffect(60, (0, 10), QColor(0, 0, 0, 80))
self.setMaskColor(QColor(0, 0, 0, 76))
self.widget.setFixedSize(
max(self.contentLabel.width(), self.titleLabel.width())+48,
self.contentLabel.y() + self.contentLabel.height() + 105
)
\ No newline at end of file
...@@ -8,7 +8,7 @@ from .mask_dialog_base import MaskDialogBase ...@@ -8,7 +8,7 @@ from .mask_dialog_base import MaskDialogBase
class MessageDialog(MaskDialogBase): class MessageDialog(MaskDialogBase):
""" Message dialog box with a mask """ """ Win10 style message dialog box with a mask """
yesSignal = pyqtSignal() yesSignal = pyqtSignal()
cancelSignal = pyqtSignal() cancelSignal = pyqtSignal()
......
...@@ -6,7 +6,7 @@ with open('README.md', encoding='utf-8') as f: ...@@ -6,7 +6,7 @@ with open('README.md', encoding='utf-8') as f:
setuptools.setup( setuptools.setup(
name="PyQt-Fluent-Widgets", name="PyQt-Fluent-Widgets",
version="0.2.7", version="0.2.8",
keywords="pyqt fluent widgets", keywords="pyqt fluent widgets",
author="zhiyiYo", author="zhiyiYo",
author_email="shokokawaii@outlook.com", author_email="shokokawaii@outlook.com",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册