[img]https://i.sstatic. net/4xDWRGLj.gif[/img]
Was ich habe: Die Taskleiste wird ausgeblendet, wenn ich den Mauszeiger außerhalb des QMenu bewege, und das QMenu bleibt geöffnet.

Relevanter PyQt6-Code, nichts Besonderes, ich erstelle einfach ein QSystemTrayIcon, innerhalb eines QMenu und einiger Test-QActions.
# Create tray, set icon and tooltip
self.tray = QSystemTrayIcon(self)
self.tray.setIcon(QIcon(":/Icons/master.png"))
self.tray.setToolTip("aaaaaaaaaa")
# Create a context menu
self.tray_menu = QMenu()
# Create quit action
quit_action = QAction(QIcon(":/Icons/exit.png"), "Quit", self)
quit_action.triggered.connect(sys.exit)
# Create test action
test_action = QAction(QIcon(":/Icons/exit.png"), "Check Version", self)
# Create get help action
get_help_action = QAction(QIcon(":/Icons/get_help.png"), "Get Help", self)
# Add actions
self.tray_menu.addAction(test_action)
self.tray_menu.addAction(get_help_action)
self.tray_menu.addAction(quit_action)
# Connect the tray icon activation event
self.tray.activated.connect(self.tray_icon_clicked)
# Fix background overflow
self.tray_menu.setWindowFlags(self.tray_menu.windowFlags() | Qt.WindowType.FramelessWindowHint)
self.tray_menu.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
def minimize_to_tray(self):
self.hide()
self.tray.show()
def restore_from_tray(self):
self.show()
self.tray.hide()
def tray_icon_clicked(self, reason):
# Left click
if reason == QSystemTrayIcon.ActivationReason.Trigger:
self.restore_from_tray()
# Right click
elif reason == QSystemTrayIcon.ActivationReason.Context:
# Get the current cursor position
cursor_pos = QCursor.pos()
# Calculate the menu position: align bottom-right corner of the menu to the cursor
menu_width = self.tray_menu.sizeHint().width()
menu_height = self.tray_menu.sizeHint().height()
pos = QPoint(cursor_pos.x() - menu_width, cursor_pos.y() - menu_height)
# Show the menu at the calculated position
self.tray_menu.popup(pos)