From f7c8c0004f343f16e9fdaf29eafa68365487ffcf Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 25 Jul 2023 12:04:50 +1000 Subject: [PATCH] Workaround crash on mac platform with non-default themes --- koordinates/gui/date_filter_widget.py | 7 ++++--- koordinates/gui/range_slider.py | 20 ++++++++++++++++++++ koordinates/gui/resolution_filter_widget.py | 4 ++-- 3 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 koordinates/gui/range_slider.py diff --git a/koordinates/gui/date_filter_widget.py b/koordinates/gui/date_filter_widget.py index 4164604..59ba3b9 100644 --- a/koordinates/gui/date_filter_widget.py +++ b/koordinates/gui/date_filter_widget.py @@ -14,15 +14,16 @@ QSizePolicy ) from qgis.gui import ( - QgsRangeSlider, QgsDateEdit ) from .filter_widget_combo_base import FilterWidgetComboBase from ..api import DataBrowserQuery +from .range_slider import RangeSlider DATE_FORMAT = 'dd MMM yyyy' +from qgis.PyQt.QtCore import QSize class ClearableDateEdit(QgsDateEdit): @@ -66,7 +67,7 @@ def __init__(self, parent): published_date_label.setFont(bold_font) vl.addWidget(published_date_label) - self.published_date_slider = QgsRangeSlider() + self.published_date_slider = RangeSlider() self.published_date_slider.setMinimumHeight(self.fontMetrics().height()) vl.addWidget(self.published_date_slider) @@ -94,7 +95,7 @@ def __init__(self, parent): updated_date_label.setFont(bold_font) vl.addWidget(updated_date_label) - self.updated_date_slider = QgsRangeSlider() + self.updated_date_slider = RangeSlider() self.updated_date_slider.setMinimumHeight(self.fontMetrics().height()) vl.addWidget(self.updated_date_slider) diff --git a/koordinates/gui/range_slider.py b/koordinates/gui/range_slider.py new file mode 100644 index 0000000..d4e2c71 --- /dev/null +++ b/koordinates/gui/range_slider.py @@ -0,0 +1,20 @@ +import platform +from qgis.PyQt.QtCore import QSize +from qgis.gui import QgsRangeSlider + + +class RangeSlider(QgsRangeSlider): + """ + Avoids a crash when non-standard application themes are used on the + mac platform. + + Relates to https://bugreports.qt.io/browse/QTBUG-43398 + https://bugreports.qt.io/browse/QTBUG-44316?focusedCommentId=272257 + """ + + def sizeHint(self): + if platform.system() == 'Darwin': + # sizeHint crashes on mac for hidden QSlider widgets + return QSize(100, 30) + + return super().sizeHint() diff --git a/koordinates/gui/resolution_filter_widget.py b/koordinates/gui/resolution_filter_widget.py index 9492697..d411195 100644 --- a/koordinates/gui/resolution_filter_widget.py +++ b/koordinates/gui/resolution_filter_widget.py @@ -6,10 +6,10 @@ QHBoxLayout, QLabel ) -from qgis.gui import QgsRangeSlider from .filter_widget_combo_base import FilterWidgetComboBase from ..api import DataBrowserQuery +from .range_slider import RangeSlider class ResolutionFilterWidget(FilterWidgetComboBase): @@ -22,7 +22,7 @@ def __init__(self, parent): self.drop_down_widget = QWidget() vl = QVBoxLayout() - self.slider = QgsRangeSlider() + self.slider = RangeSlider() self.slider.setMinimumHeight(self.fontMetrics().height()) vl.addWidget(self.slider)