zhiyiYo / PyQt-Fluent-Widgets

A fluent design widgets library based on C++ Qt/PyQt/PySide. Make Qt Great Again.
https://qfluentwidgets.com
GNU General Public License v3.0
5.61k stars 541 forks source link

QApplication.screenAt()返回None引发报错 #253

Closed zqymoe closed 10 months ago

zqymoe commented 1 year ago

Description 鼠标放在任务栏,程序启动时,QApplication.screenAt()会出现返回None的情况,引发RoundMenu类报错。

Trackback

Traceback (most recent call last):
  File "D:\CodeWorkplace\VSCodeWorkplace\QuickAssistant/src\SystemTray.py", line 24, in slot_activated
    self.menu.exec(self.geometry().topLeft(), ani=True)
  File "D:\Python311\Lib\site-packages\qfluentwidgets\components\widgets\menu.py", line 591, in exec
    self.aniManager.exec(pos)
  File "D:\Python311\Lib\site-packages\qfluentwidgets\components\widgets\menu.py", line 694, in exec
    pos = self._endPosition(pos)
          ^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Python311\Lib\site-packages\qfluentwidgets\components\widgets\menu.py", line 641, in _endPosition
    rect = QApplication.screenAt(QCursor.pos()).availableGeometry()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'availableGeometry'
Traceback (most recent call last):
  File "D:\CodeWorkplace\VSCodeWorkplace\QuickAssistant/src/main.py", line 16, in <module>
    sti = SystemTrayIcon()
          ^^^^^^^^^^^^^^^^
  File "D:\CodeWorkplace\VSCodeWorkplace\QuickAssistant/src\SystemTray.py", line 16, in __init__
    self.menu.addAction(self.action_shortcut)
  File "D:\Python311\Lib\site-packages\qfluentwidgets\components\widgets\menu.py", line 295, in addAction
    self.view.addItem(item)
  File "D:\Python311\Lib\site-packages\qfluentwidgets\components\widgets\menu.py", line 145, in addItem
    self.adjustSize()
  File "D:\Python311\Lib\site-packages\qfluentwidgets\components\widgets\menu.py", line 161, in adjustSize
    ss = QApplication.screenAt(QCursor.pos()).availableSize()
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'availableSize'
zhiyiYo commented 1 year ago

需要最小复现代码和环境信息

Zinc23333 commented 1 year ago

目前我复现了该bug,该bug是由多台显示器引起的

环境: 系统: Archlinux (Kde/Wayland) python:3.8及3.11

我分别测试了PyQt5和PySide6,均会复现该问题

运行example/gallery/demo.py 在笔记本连接了多台显示器,会抛出该异常; 不连接外接显示器时,不会抛出该异常

Zinc23333 commented 1 year ago

目前我复现了该bug,该bug是由多台显示器引起的

环境: 系统: Archlinux (Kde/Wayland) python:3.8及3.11

我分别测试了PyQt5和PySide6,均会复现该问题

运行example/gallery/demo.py 在笔记本连接了多台显示器,会抛出该异常; 不连接外接显示器时,不会抛出该异常

为又试了下,似乎仅在 DE 为Wayland 下会出现该问题, 在 X11 下不会报该错误

zhiyiYo commented 1 year ago

QApplication.screenAt(QCursor.pos()) 改成 QApplication.screenAt(self.menu.window().pos()) 可能更为合适

zhiyiYo commented 10 months ago

现在应该不会报错了