Skip to content

Commit

Permalink
Preferences: Adjust separators width when its dialog is resized
Browse files Browse the repository at this point in the history
This is only necessary on Mac.
  • Loading branch information
ccordoba12 committed Oct 22, 2023
1 parent dd6078a commit 5f50102
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions spyder/plugins/preferences/widgets/configdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ConfigDialog(QDialog, SpyderFontsMixin):
# Constants
ITEMS_MARGIN = 2 * AppStyle.MarginSize
ITEMS_PADDING = AppStyle.MarginSize
CONTENTS_MAX_WIDTH = 230
CONTENTS_WIDTH = 230
ICON_SIZE = 20

def __init__(self, parent=None):
Expand All @@ -57,6 +57,7 @@ def __init__(self, parent=None):
SpyderFontType.Interface, font_size_delta=1
)
self._is_shown = False
self._separators = []

# Widgets
self.pages_widget = QStackedWidget(self)
Expand Down Expand Up @@ -84,7 +85,7 @@ def __init__(self, parent=None):
self.contents_widget.setCurrentRow(0)
self.contents_widget.setObjectName('configdialog-contents')
self.contents_widget.setIconSize(QSize(self.ICON_SIZE, self.ICON_SIZE))
self.contents_widget.setFixedWidth(self.CONTENTS_MAX_WIDTH)
self.contents_widget.setFixedWidth(self.CONTENTS_WIDTH)

# Don't show horizontal scrollbar because it doesn't look good. Instead
# we show tooltips if the text doesn't fit in contents_widget width.
Expand Down Expand Up @@ -198,6 +199,9 @@ def add_separator(self):
# pages_widget indexes.
self.pages_widget.addWidget(QWidget(self))

# Save separators to perform certain operations only on them
self._separators.append(hline)

def add_page(self, page):
# Signals
self.check_settings.connect(page.check_settings)
Expand Down Expand Up @@ -354,6 +358,34 @@ def _adjust_items_margin(self):

self.setStyleSheet(self._css.toString())

def _adjust_separators_width(self):
"""
Adjust the width of separators present in contents_widget depending on
if its vertical scrollbar is visible.
Notes
-----
We need to do this only in Mac because Qt doesn't set the widths
correctly when there are elided items.
"""
if sys.platform == 'darwin':
scrollbar = self.contents_widget.verticalScrollBar()
for sep in self._separators:
if self.CONTENTS_WIDTH != 230:
raise ValueError(
"The values used here for the separators' width were "
"the ones reported by Qt for a contents_widget width "
"of 230px. Since this value changed, you need to "
"update them."
)

# These are the values reported by Qt when CONTENTS_WIDTH = 230
# and the interface language is English.
if scrollbar.isVisible():
sep.setFixedWidth(188)
else:
sep.setFixedWidth(204)

def _generate_stylesheet(self):
"""Generate stylesheet for this widget as qstylizer object."""
# Use special tabbar stylesheet for as the base one and then extend it.
Expand Down Expand Up @@ -425,4 +457,5 @@ def _on_resize_event(self):
"""Method to run when Qt emits a resize event."""
self._add_tooltips()
self._adjust_items_margin()
self._adjust_separators_width()
self.sig_size_changed.emit(self.size())

0 comments on commit 5f50102

Please sign in to comment.