Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Prevent first time render glitch by calling position logic via a timer in showEvent (Menus) #22355

Merged
merged 5 commits into from
Aug 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
dalthviz marked this conversation as resolved.
Show resolved Hide resolved
"""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