Not much info I've found, but looks like this snippet should works:
import sys
from PySide2.QtWidgets import QApplication, QMenu, QPushButton, QSystemTrayIcon, QWidgetAction
app = QApplication(sys.argv)
menu = QMenu()
button = QPushButton("yoba")
action = QWidgetAction(menu)
action.setDefaultWidget(button)
menu.addAction(action)
menu.addAction("Quit").triggered.connect(sys.exit)
tray = QSystemTrayIcon()
tray.setContextMenu(menu)
tray.show()
sys.exit(app.exec_())
But, I see only Quit
item and empty item above, no push button appear. So, the question is "how to add custom widgets to tray menu?"
Ok, looks like this is a bug: https://bugreports.qt.io/browse/QTBUG-26840
Since if call menu.show()
instead of tray.show()
everything is fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.