In QMenu, the mouse hover cannot be set
-
wrote on 18 Mar 2025, 02:42 last edited by
Here is a test case:
from PyQt6.QtWidgets import QApplication, QSystemTrayIcon, QMenu from PyQt6.QtGui import QIcon, QAction class TrayIconApp: def __init__(self): self.app = QApplication([]) self.tray_icon = QSystemTrayIcon() self.tray_icon.setIcon(QIcon("../Pets/MengJi_pro.png")) self.tray_menu = QMenu() self.tray_menu.setStyleSheet(""" QMenu::item { padding: 5px 20px; text-align: center; background-color: white; color: black; } QMenu::item:hover { background-color: #0078d7; color: white; } QMenu::item:pressed { background-color: #005bb5; color: white; } """) self.show_action = QAction("Show", self.tray_menu) self.exit_action = QAction("Exit", self.tray_menu) self.tray_menu.addAction(self.show_action) self.tray_menu.addAction(self.exit_action) self.tray_icon.setContextMenu(self.tray_menu) self.tray_icon.show() self.app.exec() if __name__ == "__main__": app = TrayIconApp()
After I run the code, right click the icon and hover the mouse on the widget, nothing changes in color. I think this is a bug.
1/1