You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PyQt6中QSystemTrayIcon.Information无法使用的问题求助

解决PyQt6中QSystemTrayIcon.showMessage图标报错问题

在PyQt6中,消息图标的枚举组织方式和PyQt5不同,QSystemTrayIcon.Information这类枚举已被移除,替代方案有两种:

方案1:使用Qt.MessageIcon枚举

从PyQt6.QtCore导入Qt,将原代码中的QSystemTrayIcon.Information替换为Qt.MessageIcon.Information:

from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QSystemTrayIcon

# ...

def closeEvent(self, event):
    event.ignore()
    self.hide()
    self.tray_icon.showMessage(
        "Tray Program", 
        "Application was minimized to Tray", 
        Qt.MessageIcon.Information, 
        2000
    )

方案2:使用QMessageBox枚举

从PyQt6.QtWidgets导入QMessageBox,用QMessageBox.Information替代原枚举:

from PyQt6.QtWidgets import QMessageBox, QSystemTrayIcon

# ...

def closeEvent(self, event):
    event.ignore()
    self.hide()
    self.tray_icon.showMessage(
        "Tray Program", 
        "Application was minimized to Tray", 
        QMessageBox.Information, 
        2000
    )

说明

PyQt6对枚举做了统一归类,原PyQt5中分散在各控件类下的通用枚举(如消息图标),被整合到Qt.MessageIcon这类核心枚举类中,同时QMessageBox的图标枚举值与Qt.MessageIcon兼容,两种方式都能正常显示信息图标。

内容的提问来源于stack exchange,提问作者Alex B

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 16:07:12