simgunz / anki21-addons_minimize-to-tray

Anki add-on that adds an icon to the system tray in order to allow minimizing Anki
https://ankiweb.net/shared/info/85158043
GNU General Public License v3.0
18 stars 3 forks source link

Right click menu shows up in the wrong spot #1

Closed encody closed 2 years ago

encody commented 6 years ago

Thanks for the addon, so far so good.

I'm on Windows 10, and when I right-click on the icon, this is what appears:

image

The right-click menu is misplaced: instead of appearing right next to the mouse, it appears in the lower-right corner of the screen.

Anki installation: Version 2.1.4 Qt 5.9.2 PyQt 5.9

simgunz commented 6 years ago

Thanks for reporting the bug. I think this is likely related to Qt on Windows. I'll have a look soon though.

simgunz commented 6 years ago

I have investigated this issue further and using the test script below the menu is displayed in the correct position. So the issue seems related to my implementation or to how anki manages the add on.

import sys

from PyQt5.QtGui import QIcon, QPixmap  
from PyQt5.QtWidgets import QApplication, QMenu, QSystemTrayIcon, QDialog

class App:
  def __init__(self):
    # Create a Qt application
    self.app = QApplication(sys.argv)

    icon = QIcon("C:\sharedLinux\home.png")
    menu = QMenu()
    settingAction = menu.addAction("setting")
    settingAction.triggered.connect(self.setting)
    exitAction = menu.addAction("exit")
    exitAction.triggered.connect(sys.exit)

    self.tray = QSystemTrayIcon()
    self.tray.setIcon(icon)
    self.tray.setContextMenu(menu)
    self.tray.show()
    self.tray.setToolTip("unko!")

  def run(self):
    # Enter Qt application main loop
    self.app.exec_()
    sys.exit()

  def setting(self):
    self.dialog = QDialog()
    self.dialog.setWindowTitle("Setting Dialog")
    self.dialog.show()

if __name__ == "__main__":
  app = App()
  app.run()
simgunz commented 6 years ago

I have tried to ask on the QtForum: https://forum.qt.io/topic/96026/qmenu-in-qsytemtrayicon-misplaced-in-windows-10

simgunz commented 3 years ago

Does this issue still happen?