From 3423fb0d56b3a05a8d8ce4cb0ca5c30146c2912b Mon Sep 17 00:00:00 2001 From: jcornall Date: Mon, 16 Dec 2024 15:53:47 +0000 Subject: [PATCH] Rewrite UISliderWidget class to take a QDoubleSpinBox as input --- eqt/ui/UISliderWidget.py | 31 ++++++++++++++++++----- examples/dialog_example_3_save_default.py | 4 +-- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/eqt/ui/UISliderWidget.py b/eqt/ui/UISliderWidget.py index c5722cb..e1656b0 100644 --- a/eqt/ui/UISliderWidget.py +++ b/eqt/ui/UISliderWidget.py @@ -6,18 +6,35 @@ class UISliderWidget(QSlider): '''Creates a Slider widget which updates a QLabel with its value (which may be scaled to a non-integer value by setting the scale_factor)''' - def __init__(self, label, scale_factor=1): + def __init__(self, dspinbox, scale_factor=1, parent=None): QSlider.__init__(self) - self.label = label + self.parent = parent self.scale_factor = scale_factor + self.setOrientation(QtCore.Qt.Horizontal) self.setFocusPolicy(QtCore.Qt.StrongFocus) self.setTickPosition(QSlider.TicksBelow) - self.valueChanged.connect(self.show_slider_value) + + self.sliderPressed.connect(self.update_dspinbox) + self.sliderMoved.connect(self.update_dspinbox) + self.sliderReleased.connect(self.update_dspinbox) + + self.dspinbox = dspinbox + self.dspinbox.setMinimum(0.00) + self.dspinbox.setMaximum(100.00) + self.dspinbox.setValue(0.00) + self.dspinbox.editingFinished.connect(self.update_slider) def get_slider_value(self): - return self.value() * self.scale_factor + return self.value() + + def get_dspinbox_value(self): + return self.dspinbox.value() + + def update_slider(self): + dspinbox_value = int(self.get_dspinbox_value()) + self.setValue(dspinbox_value) - def show_slider_value(self): - value = self.get_slider_value() - self.label.setText(str(value)) + def update_dspinbox(self): + slider_value = float(self.get_slider_value()) + self.dspinbox.setValue(slider_value) diff --git a/examples/dialog_example_3_save_default.py b/examples/dialog_example_3_save_default.py index 27c8cc5..de7398d 100644 --- a/examples/dialog_example_3_save_default.py +++ b/examples/dialog_example_3_save_default.py @@ -3,7 +3,7 @@ import utilitiesForExamples as utex from PySide2 import QtWidgets -from eqt.ui import FormDialog +from eqt.ui import UISliderWidget class MainUI(QtWidgets.QMainWindow): @@ -20,7 +20,7 @@ def __init__(self, parent=None): widg.setLayout(layout) self.setCentralWidget(widg) - self.dialog = FormDialog(parent=self, title='Example') + self.uislider = UISliderWidget() self.openFormDialog() self.show()