Skip to content

Commit a3eccea

Browse files
authored
Widen dock separators to make them easier to grab (#277) (#595)
* Widen dock separators to make them easier to grab (#277) * Reword the dock separator comment * Widen the separators with a style proxy instead of a stylesheet A stylesheet on the main window moves its whole widget subtree to QStyleSheetStyle, which drops palette based theming (the syntax highlighting regression seen in review). * Reuse the main_clean fixture in the separator test --------- Co-authored-by: Haozhe Zhang <HaozheZhang6@users.noreply.github.com>
1 parent f75f55f commit a3eccea

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

‎cq_editor/main_window.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
QAction,
1313
QApplication,
1414
QMenu,
15+
QProxyStyle,
16+
QStyle,
1517
)
1618
from logbook import Logger
1719
import cadquery as cq
@@ -63,6 +65,23 @@ def new_stdout_write(text: str):
6365
PRINT_REDIRECTOR = _PrintRedirectorSingleton()
6466

6567

68+
class DockSeparatorStyle(QProxyStyle):
69+
"""Widens the dock separators so that they are easier to grab (#277).
70+
71+
A style proxy is used instead of a stylesheet because setting a stylesheet
72+
on the main window moves its whole widget subtree to QStyleSheetStyle,
73+
which discards palette based theming (e.g. editor syntax highlighting).
74+
"""
75+
76+
def pixelMetric(self, metric, option=None, widget=None):
77+
78+
extent = super().pixelMetric(metric, option, widget)
79+
if metric == QStyle.PM_DockWidgetSeparatorExtent:
80+
return max(extent, 6)
81+
82+
return extent
83+
84+
6685
class MainWindow(QMainWindow, MainMixin):
6786

6887
name = "CQ-Editor"
@@ -100,6 +119,11 @@ def __init__(self, parent=None, filename=None):
100119
self.viewer = OCCViewer(self)
101120
self.setCentralWidget(self.viewer.canvas)
102121

122+
# Make sure the dock separators are wide enough to grab on high-DPI displays.
123+
# setStyle does not take ownership, so keep a reference on self.
124+
self._separator_style = DockSeparatorStyle()
125+
self.setStyle(self._separator_style)
126+
103127
self.prepare_panes()
104128
self.registerComponent("viewer", self.viewer)
105129
self.prepare_toolbar()

‎tests/test_app.py‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@
1212
import cadquery as cq
1313

1414
from PyQt5.QtCore import Qt, QSettings, QPoint, QEvent, QSize
15-
from PyQt5.QtWidgets import QFileDialog, QMessageBox
15+
from PyQt5.QtWidgets import (
16+
QApplication,
17+
QFileDialog,
18+
QMessageBox,
19+
QStyle,
20+
QStyleFactory,
21+
)
1622
from PyQt5.QtGui import QMouseEvent
1723

1824
from cq_editor.__main__ import MainWindow
25+
from cq_editor.main_window import DockSeparatorStyle
1926
from cq_editor.widgets.editor import Editor
2027
from cq_editor.cq_utils import export, get_occ_color
2128

@@ -1708,6 +1715,30 @@ def test_launch_syntax_error(tmp_path):
17081715
assert win.isVisible()
17091716

17101717

1718+
def test_dock_separator_width(main_clean):
1719+
1720+
qtbot, win = main_clean
1721+
1722+
# separators are widened through a style proxy, not a stylesheet: a
1723+
# stylesheet on the main window would break palette based theming (#595)
1724+
assert win.styleSheet() == ""
1725+
assert win.style().pixelMetric(QStyle.PM_DockWidgetSeparatorExtent, None, win) >= 6
1726+
1727+
# child widgets keep the application style
1728+
editor = win.components["editor"]
1729+
assert editor.style().objectName() == QApplication.instance().style().objectName()
1730+
1731+
1732+
def test_dock_separator_style_widens_small_extents(qtbot):
1733+
1734+
base = QStyleFactory.create("Windows")
1735+
assert base.pixelMetric(QStyle.PM_DockWidgetSeparatorExtent) < 6
1736+
1737+
style = DockSeparatorStyle(base)
1738+
1739+
assert style.pixelMetric(QStyle.PM_DockWidgetSeparatorExtent) == 6
1740+
1741+
17111742
code_import_module_makebox = """
17121743
from module_makebox import *
17131744
z = 1

0 commit comments

Comments
 (0)