Sandman42
Sandman42

Reputation: 75

QMenu for a tray icon doesn't show

I’m trying to create a mouse right-click menu for a QSysTrayIcon, but the menu doesn’t show.

What I do is this:

def create_tray_icon(self):
    # Create the application instance
    self.app = QApplication(sys.argv)
    self.icon = QSystemTrayIcon()
    self.icon.setIcon(QIcon("MyIcon.ico"))
    self.icon.setToolTip(f"Row1\nRow2\n"
                         f"Row3")

    # Create a context menu for the tray icon
    menu = QMenu()

    # Add a "Quit" option to the menu
    quit_action = QAction("Quit")
    quit_action.triggered.connect(self.app.quit)
    menu.addAction(quit_action)

    # Set the context menu for the tray icon
    self.icon.setContextMenu(menu)

    # Show the tray icon
    self.icon.show()

The tray icon shows, the tooltip, too, but if I right click the icon I don’t see the Quit option.

I’m on windows 11

What am I doing wrong?

Thanks

Upvotes: 0

Views: 24

Answers (0)

Related Questions