I wrote a program that creates an icon in the system tray and clicking the right mouse button displays a context menu with 2 points Notes and Quit, Notes item is a submenu of the one-point Create new note. But why the item is not displayed Notes. Why?
from PyQt4 import QtCore, QtGui
import sys
def main():
app = QtGui.QApplication(sys.argv)
tray = QtGui.QSystemTrayIcon()
icon = app.style().standardIcon(QtGui.QStyle.SP_DesktopIcon)
tray.setIcon(icon)
tray.show()
CreateMenu(tray, app)
sys.exit(app.exec_())
def CreateMenu(tray, app):
m1 = QtGui.QMenu("Menu 1")
m2 = QtGui.QMenu("Notes")
m2.addAction("Create new note")
m1.addMenu(m2)
m1.addSeparator()
m1.addAction("Quit", app.quit)
tray.setContextMenu(m1)
if __name__ == '__main__':
main()
Just pass the
m1menu as a parent tom2and it will work.Tested on my Ubuntu box.