Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

pyqt minimize to tray icon

import sys
from PyQt4.QtGui import QAction, QApplication, QFrame, QIcon, 
    QMainWindow, QMenu, QSystemTrayIcon
from PyQt4.QtCore import SIGNAL

class MyApp(QMainWindow):
    def __init__(self, parent, title):
        super(QMainWindow, self).__init__(parent)
        self.exitOnClose = False
        exit = QAction(QIcon(), "Exit", self)
        self.connect(exit, SIGNAL("triggered()"), self.exitEvent)
        self.trayIcon = QSystemTrayIcon(QIcon(), self)
        menu = QMenu(self)
        menu.addAction(exit)
        self.trayIcon.setContextMenu(menu)
        self.connect(self.trayIcon, 
            SIGNAL("activated(QSystemTrayIcon::ActivationReason)"), 
            self.trayIconActivated)
        self.trayIcon.show()
        self.trayIcon.showMessage("MyApp is running!", "Click to open window
Right click for menu" )

    def trayIconActivated(self, reason):
        if reason == QSystemTrayIcon.Context:
            self.trayIcon.contextMenu().show()
        elif reason == QSystemTrayIcon.Trigger:
            self.show()
            self.raise_()

    def closeEvent(self, event):
        if self.exitOnClose:
            self.trayIcon.hide()
            del self.trayIcon
            event.accept()
        else:
            self.hide()
            event.setAccepted(True)
            event.ignore()

    def exitEvent(self):
        self.exitOnClose = True
        self.close()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    myapp = MyApp(None, "My System Tray App")
    app.exec_()
Comment

PREVIOUS NEXT
Code Example
Csharp :: asp.net format datetime 
Csharp :: random string generator c# 
Csharp :: json serialization 
Csharp :: Get Last Access Time Of Directory C# 
Csharp :: defualtsize UWP c# 
Csharp :: how to reload app.config file at runtime in c# 
Csharp :: c# string right extension 
Csharp :: c# parse number from string 
Csharp :: static class can have non static member in c# 
Csharp :: append an array in c# 
Csharp :: deploy .net core 
Csharp :: c# modulo 
Csharp :: defining vectors in c# 
Csharp :: declare string array c# without size 
Csharp :: unity pause coroutine 
Csharp :: longest substring without repeating characters leetcode 
Csharp :: how to get mouse position c# 
Csharp :: finding values in the registry 
Csharp :: how to change all values in dictionary c# 
Csharp :: preprocessors 
Csharp :: Get all images from folder asp.net 
Csharp :: c# read xml tag value 
Csharp :: c# console delete last character 
Csharp :: unity pickup and drop objects 
Csharp :: how to make 3d field of view in unity 
Csharp :: how to serialize a property in unity 
Csharp :: global variables unity 
Csharp :: join string c# 
Csharp :: how to round to nearest number in array c# 
Csharp :: c# draggable controls 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =