本文介绍了PyQt5 QSystemTrayIcon 在实际托盘之外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 PyQt5 应用程序,这只是一个例子,并没有做任何事情:

I have simple PyQt5 application, which is just an example, and doesn't do anything:

#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import sys
from PyQt5 import QtWidgets, QtCore, QtGui 


class SystemTrayIcon(QtWidgets.QSystemTrayIcon):

    def __init__(self, icon, parent=None):
        super(SystemTrayIcon, self).__init__(icon, parent)
        menu = QtWidgets.QMenu(parent)
        exitAction = menu.addAction("Exit")
        exitAction.triggered.connect(parent.close)
        self.setContextMenu(menu)


class MainWindow(QtWidgets.QWidget):
    def __init__(self):
        super(MainWindow, self).__init__()         
        self.initUI()

    def initUI(self):      
        self.setGeometry(300, 300, 250, 150)
        self.setWindowTitle('Icon')
        self.tray_icon = SystemTrayIcon(QtGui.QIcon('test.ico'), self)
        self.tray_icon.show()
        self.show()


if __name__ == '__main__':
    app = QtWidgets.QApplication([])
    w = MainWindow()
    sys.exit(app.exec_())

启动后,它显示主窗口和托盘图标.但是托盘图标不在托盘中.它在左上角.

After start, it shows main window and tray icon. But tray icon isn't in tray. It is in left-upper corner.

我该如何解决这个问题?此代码在 Windows 7、Mac OS X 和带有 KDE 的 Archlinux 上正常工作.所以问题可能在 Ubuntu DE 中.

How do I fix this? This code works normally on Windows 7, Mac OS X, and Archlinux with KDE. So problem probably in Ubuntu DE.

我使用最新的 ubuntu 14.04 amd64,python 3,PyQt5,Qt 版本是 5.2.1

I use latest ubuntu 14.04 amd64, python 3, PyQt5, Qt version is 5.2.1

推荐答案

It's known bug;查看此错误报告.

It's known bug; see this bug report.

显然,它将在下一个版本中修复.

Apparently, it will be fixed in next releases.

这篇关于PyQt5 QSystemTrayIcon 在实际托盘之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 17:29