Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: InforBar在主界面hide后finished,会导致主进程退出 #1006

Open
HomerKwok opened this issue Nov 5, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@HomerKwok
Copy link

What happened?

在给主程序增加托盘图标时,重写了closeEvent,隐藏主界面并忽略关闭事件。但在显示消息条时点击关闭按钮,过会儿程序会退出。
问题点:

def closeEvent(self, e):
    self.closedSignal.emit()
    self.deleteLater()

解决办法:

def closeEvent(self, e):
    self.closedSignal.emit()
    self.deleteLater()
    e.ignore()

Operation System

WIn11 23H2

Python Version

3.11.1

PyQt/PySide Version

5.15.10

PyQt/PySide-Fluent-Widgets Version

1.5.7

How to Reproduce?

使用example里的gallery程序,在MainWIndow重写closeEvent:

def closeEvent(self, e):  
    self.hide()  
    e.ignore()  

运行gallery,在消息页面点击显示一条消息条,在消息条消失前点击窗口关闭按钮,等待几秒消息条finished,然后程序退出了,exit code 0.

Minimum code

# coding:utf-8
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout

from qfluentwidgets import InfoBarIcon, InfoBar, PushButton, InfoBarPosition


class Demo(QWidget):

    def __init__(self):
        super().__init__()

        self.hBoxLayout = QHBoxLayout(self)
        self.button1 = PushButton('Information', self)

        self.button1.clicked.connect(self.createInfoInfoBar)

        self.hBoxLayout.addWidget(self.button1)
        self.hBoxLayout.setContentsMargins(30, 0, 30, 0)

        self.resize(700, 700)

    def createInfoInfoBar(self):
        content = "My name is kira yoshikake, 33 years old. Living in the villa area northeast of duwangting, unmarried. I work in Guiyou chain store. Every day I have to work overtime until 8 p.m. to go home. I don't smoke. The wine is only for a taste. Sleep at 11 p.m. for 8 hours a day. Before I go to bed, I must drink a cup of warm milk, then do 20 minutes of soft exercise, get on the bed, and immediately fall asleep. Never leave fatigue and stress until the next day. Doctors say I'm normal."
        w = InfoBar(
            icon=InfoBarIcon.INFORMATION,
            title='Title',
            content=content,
            orient=Qt.Vertical,    # vertical layout
            isClosable=True,
            position=InfoBarPosition.TOP_RIGHT,
            duration=2000,
            parent=self
        )
        w.addWidget(PushButton('Action'))
        w.show()

    def closeEvent(self, e) -> None:
        self.hide()
        e.ignore()


if __name__ == '__main__':
    # enable dpi scale
    QApplication.setHighDpiScaleFactorRoundingPolicy(
        Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
    QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
    QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)

    app = QApplication(sys.argv)
    w = Demo()
    w.show()
    app.exec_()
@HomerKwok HomerKwok added the bug Something isn't working label Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant