I am creating a system tray application in Mac (El Capitan 10.11.3) using Pyside. However, I am not able to set certain menu entry as disabled, particularly when its a child menu. The setDisabled(True)
works for parent menu entry though.
The same code works in Ubuntu/Linux and the child menu entry is disabled.
As the original code is too long to display here, I have made a simple sys tray application that exhibits the same problem.
import sys
from PySide import QtGui
class SystemTrayIcon(QtGui.QSystemTrayIcon):
def __init__(self, icon, parent=None):
QtGui.QSystemTrayIcon.__init__(self, icon, parent)
menu = QtGui.QMenu(parent)
menu.addAction("Item 1")
menu.addAction("Item 2")
disabledItem = menu.addAction("Item 3 Disabled")
disabledItem.setDisabled(True)
subMenu = menu.addMenu("Item 4 with sub menu")
subMenu.addAction("SubMenu 1")
disabledSubMenu = subMenu.addAction("SubMenu 2 Disabled (Not Working)")
disabledSubMenu.setDisabled(True)
disabledSubMenu2 = subMenu.addMenu("SubMenu Disabled")
disabledSubMenu2.setDisabled(True)
self.setContextMenu(menu)
def main():
app = QtGui.QApplication(sys.argv)
style = app.style()
w = QtGui.QWidget()
trayIcon = SystemTrayIcon(QtGui.QIcon(style.standardPixmap(QtGui.QStyle.SP_FileIcon)))
trayIcon.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
From the above example, Item 3 Disabled (which is a parent menu) is disabled when using setDisabled(True)
. But SubMenu 2 Disabled is not working, which is a child menu to Item 4 with sub menu.
One thing to note is SubMenu Disabled is working when its set as addMenu
item than using addAction
.
Any help regarding this is highly appreciated. Thanks!