Skip to content

Commit

Permalink
Rewrite UISliderWidget class to take a QDoubleSpinBox as input
Browse files Browse the repository at this point in the history
  • Loading branch information
jcornall committed Dec 16, 2024
1 parent c3ae2b4 commit 3423fb0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
31 changes: 24 additions & 7 deletions eqt/ui/UISliderWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions examples/dialog_example_3_save_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()
Expand Down

0 comments on commit 3423fb0

Please sign in to comment.