示例#1
0
    def __init__(self, title, message, item, *args, ntype=0, callback=None, **kwargs):
        super(NotificationItem, self).__init__(*args, **kwargs)
        self.item = item
        self.callback = callback
        layout = QHBoxLayout(self, spacing=0)
        layout.setContentsMargins(0, 0, 0, 0)
        self.bgWidget = QWidget(self)  # 背景控件, 用于支持动画效果
        layout.addWidget(self.bgWidget)

        layout = QGridLayout(self.bgWidget)
        layout.setHorizontalSpacing(15)
        layout.setVerticalSpacing(10)

        # 标题左边图标
        layout.addWidget(
            QLabel(self, pixmap=NotificationIcon.icon(ntype)), 0, 0)

        # 标题
        self.labelTitle = QLabel(title, self)
        font = self.labelTitle.font()
        font.setBold(True)
        font.setPixelSize(22)
        self.labelTitle.setFont(font)

        # 关闭按钮
        self.labelClose = QLabel(
            self, cursor=Qt.PointingHandCursor, pixmap=NotificationIcon.icon(NotificationIcon.Close))

        # 消息内容
        self.labelMessage = QLabel(
            message, self, cursor=Qt.PointingHandCursor, wordWrap=True, alignment=Qt.AlignLeft | Qt.AlignTop)
        font = self.labelMessage.font()
        font.setPixelSize(20)
        self.labelMessage.setFont(font)
        self.labelMessage.adjustSize()

        # 添加到布局
        layout.addWidget(self.labelTitle, 0, 1)
        layout.addItem(QSpacerItem(
            40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum), 0, 2)
        layout.addWidget(self.labelClose, 0, 3)
        layout.addWidget(self.labelMessage, 1, 1, 1, 2)

        # 边框阴影
        effect = QGraphicsDropShadowEffect(self)
        effect.setBlurRadius(12)
        effect.setColor(QColor(0, 0, 0, 25))
        effect.setOffset(0, 2)
        self.setGraphicsEffect(effect)

        self.adjustSize()

        # 5秒自动关闭
        self._timer = QTimer(self, timeout=self.doClose)
        self._timer.setSingleShot(True)  # 只触发一次
        self._timer.start(5000)
示例#2
0
    def __init__(self,
                 title,
                 message,
                 item,
                 *args,
                 ntype=0,
                 callback=None,
                 **kwargs):
        super(NotificationItem, self).__init__(*args, **kwargs)
        self.item = item
        self.callback = callback
        layout = QHBoxLayout(self, spacing=0)
        layout.setContentsMargins(0, 0, 0, 0)
        # Фоновые элементы управления, используемые для поддержки эффектов анимации
        self.bgWidget = QWidget(self)
        layout.addWidget(self.bgWidget)

        layout = QGridLayout(self.bgWidget)
        layout.setHorizontalSpacing(10)
        layout.setVerticalSpacing(5)

        # Значок слева от title
        layout.addWidget(QLabel(self, pixmap=NotificationIcon.icon(ntype)), 0,
                         0)

        # title
        self.labelTitle = QLabel(title, self)
        font = self.labelTitle.font()
        font.setBold(True)
        font.setPixelSize(15)
        self.labelTitle.setFont(font)

        # Кнопка закрытия
        self.labelClose = QLabel(self,
                                 cursor=Qt.PointingHandCursor,
                                 pixmap=NotificationIcon.icon(
                                     NotificationIcon.Close))

        # Содержание сообщения
        self.labelMessage = QLabel(message,
                                   self,
                                   cursor=Qt.PointingHandCursor,
                                   wordWrap=True,
                                   alignment=Qt.AlignLeft | Qt.AlignTop)
        font = self.labelMessage.font()
        font.setPixelSize(10)
        self.labelMessage.setFont(font)
        self.labelMessage.adjustSize()

        layout.addWidget(self.labelTitle, 0, 1)
        layout.addItem(
            QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum), 0,
            2)
        layout.addWidget(self.labelClose, 0, 3)
        layout.addWidget(self.labelMessage, 1, 1, 1, 2)

        effect = QGraphicsDropShadowEffect(self)
        effect.setBlurRadius(12)
        effect.setColor(QColor(0, 0, 0, 25))
        effect.setOffset(0, 2)
        self.setGraphicsEffect(effect)
        self.adjustSize()
    def __init__(self,
                 title,
                 message,
                 item,
                 *args,
                 ntype=0,
                 callback=None,
                 bg_color=QColor(195, 195, 195),
                 msg_color="black",
                 **kwargs):
        super(NotificationItem, self).__init__(*args, **kwargs)
        self.item = item
        self.bg_color = bg_color
        self.callback = callback
        layout = QHBoxLayout(self, spacing=0)
        layout.setContentsMargins(0, 0, 0, 0)
        # notification item background widget
        self.bgWidget = QWidget(self)
        layout.addWidget(self.bgWidget)

        layout = QGridLayout(self.bgWidget)
        layout.setHorizontalSpacing(0)
        layout.setVerticalSpacing(0)

        layout.addWidget(QLabel(self, pixmap=NotificationIcon.icon(ntype)), 0,
                         0)

        # title
        self.labelTitle = QLabel(title, self)
        font = self.labelTitle.font()
        font.setBold(True)
        font.setPixelSize(16)
        self.labelTitle.setFont(font)
        self.labelTitle.setStyleSheet(
            'color: {}; padding-left: 3px'.format(msg_color))
        # self.labelTitle.move(50, 30)

        # close button
        self.labelClose = QLabel(self,
                                 cursor=Qt.PointingHandCursor,
                                 pixmap=NotificationIcon.icon(
                                     NotificationIcon.Close))

        # notification message content
        self.labelMessage = QLabel(message,
                                   self,
                                   cursor=Qt.PointingHandCursor,
                                   wordWrap=True,
                                   alignment=Qt.AlignLeft | Qt.AlignTop)
        font = self.labelMessage.font()
        font.setPixelSize(13)
        self.labelMessage.setFont(font)
        self.labelMessage.setStyleSheet(
            'color: {}; padding-left: 3px'.format(msg_color))
        self.labelMessage.adjustSize()

        # add to the grid layout
        layout.addWidget(self.labelTitle, 0, 1)
        layout.addItem(
            QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum), 0,
            2)
        layout.addWidget(self.labelClose, 0, 3)
        layout.addWidget(self.labelMessage, 1, 1, 1, 2)

        # 边框阴影
        effect = QGraphicsDropShadowEffect(self)
        effect.setBlurRadius(12)
        effect.setColor(QColor(0, 0, 0, 25))
        effect.setOffset(0, 2)
        self.setGraphicsEffect(effect)

        self.adjustSize()

        # after 5 sec, close window
        self._timer = QTimer(self, timeout=self.doClose)
        self._timer.setSingleShot(True)
        self._timer.start(LAST_TIME)