Skip to content

Commit

Permalink
Merge pull request #22355 from dalthviz/fixes_issue_22266
Browse files Browse the repository at this point in the history
PR: Prevent first time render glitch by calling position logic via a timer in `showEvent` (Menus)
  • Loading branch information
ccordoba12 authored Aug 20, 2024
2 parents 08499f9 + aaed22f commit 48e5319
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions spyder/api/widgets/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

# Third party imports
import qstylizer.style
from qtpy.QtCore import QTimer
from qtpy.QtGui import QCursor
from qtpy.QtWidgets import QAction, QMenu, QProxyStyle, QStyle, QWidget

Expand Down Expand Up @@ -457,10 +458,8 @@ def __str__(self):
def __repr__(self):
return f"SpyderMenu('{self.menu_id}')"

# ---- Qt methods
# -------------------------------------------------------------------------
def showEvent(self, event):
"""Adjustments when the menu is shown."""
def _adjust_menu_position(self):
"""Menu position adjustment logic to follow custom style."""
if not self._is_shown:
# Reposition submenus vertically due to padding and border
if self._reposition and self._is_submenu:
Expand All @@ -487,7 +486,17 @@ def showEvent(self, event):

self.move(self.pos().x() + delta_x, self.pos().y())

super().showEvent(event)
# ---- Qt methods
# -------------------------------------------------------------------------
def showEvent(self, event):
"""Call adjustments when the menu is going to be shown."""
# To prevent race conditions which can cause partially showing a menu
# (as in spyder-ide/spyder#22266), we use a timer to queue the move
# related events after the menu is shown.
# For more info you can check:
# * https://forum.qt.io/topic/23381/showevent-not-working/3
# * https://stackoverflow.com/a/49351518
QTimer.singleShot(0, self._adjust_menu_position)


class PluginMainWidgetOptionsMenu(SpyderMenu):
Expand Down

0 comments on commit 48e5319

Please sign in to comment.