Created
April 8, 2013 17:53
-
-
Save hogelog/5338905 to your computer and use it in GitHub Desktop.
QSystemTrayIcon Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Import PySide classes | |
import sys | |
from PySide.QtCore import * | |
from PySide.QtGui import * | |
class App: | |
def __init__(self): | |
# Create a Qt application | |
self.app = QApplication(sys.argv) | |
icon = QIcon("jenkins_favicon.png") | |
menu = QMenu() | |
settingAction = menu.addAction("setting") | |
settingAction.triggered.connect(self.setting) | |
exitAction = menu.addAction("exit") | |
exitAction.triggered.connect(sys.exit) | |
self.tray = QSystemTrayIcon() | |
self.tray.setIcon(icon) | |
self.tray.setContextMenu(menu) | |
self.tray.show() | |
self.tray.setToolTip("unko!") | |
self.tray.showMessage("hoge", "moge") | |
self.tray.showMessage("fuga", "moge") | |
def run(self): | |
# Enter Qt application main loop | |
self.app.exec_() | |
sys.exit() | |
def setting(self): | |
self.dialog = QDialog() | |
self.dialog.setWindowTitle("Setting Dialog") | |
self.dialog.show() | |
if __name__ == "__main__": | |
app = App() | |
app.run() |
This worked for me just replacing PyQt5
with PySide2
. This pops the icon up on the top menu bar on macOS. Related question: how do you set the application icon on the macOS dock?
Thank you. It works great.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More info: