11import platform
22import re
3- from typing import Any
3+ from typing import Any , cast
44from PyQt6 .QtWidgets import QApplication , QWidget , QFrame , QMenu , QGraphicsDropShadowEffect
5- from PyQt6 .QtCore import QEvent , QObject , QPoint , Qt
6- from PyQt6 .QtGui import QScreen , QColor
5+ from PyQt6 .QtCore import QEvent , QPoint , Qt
6+ from PyQt6 .QtGui import QScreen , QColor
77from core .utils .win32 .blurWindow import Blur
88
99def is_windows_10 () -> bool :
@@ -99,7 +99,7 @@ def setPosition(self, alignment='left', direction='down', offset_left=0, offset_
9999 offset_left (int): Horizontal offset in pixels
100100 offset_top (int): Vertical offset in pixels
101101 """
102- parent = self .parent ()
102+ parent = cast ( QWidget , self .parent ()) # parent should be a QWidget
103103 if not parent :
104104 return
105105
@@ -124,6 +124,15 @@ def setPosition(self, alignment='left', direction='down', offset_left=0, offset_
124124 else :
125125 global_position = widget_global_pos
126126
127+ # Determine screen where the parent is
128+ screen = QApplication .screenAt (parent .mapToGlobal (parent .rect ().center ()))
129+ if screen :
130+ available_geometry = screen .availableGeometry ()
131+ # Ensure the popup fits horizontally
132+ x = max (available_geometry .left (), min (global_position .x (), available_geometry .right () - self .width ()))
133+ # Ensure the popup fits vertically
134+ y = max (available_geometry .top (), min (global_position .y (), available_geometry .bottom () - self .height ()))
135+ global_position = QPoint (x , y )
127136 self .move (global_position )
128137
129138 def showEvent (self , event ):
0 commit comments