Skip to content

Commit

Permalink
Add UISliderLEditWidget case to getWidgetState() and applyWidgetState()
Browse files Browse the repository at this point in the history
  • Loading branch information
jcornall committed Jan 2, 2025
1 parent f7517ab commit 5c595bf
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
6 changes: 6 additions & 0 deletions eqt/ui/UIFormWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from PySide2 import QtWidgets

from .UISliderLEditWidget import UISliderLEditWidget
from .UISliderWidget import UISliderWidget


Expand Down Expand Up @@ -335,6 +336,8 @@ def getWidgetState(self, widget, role=None):
widget_state['value'] = widget.isChecked()
elif isinstance(widget, (QtWidgets.QTextEdit, QtWidgets.QPlainTextEdit)):
widget_state['value'] = widget.toPlainText()
elif isinstance(widget, UISliderLEditWidget) or isinstance(widget, QtWidgets.QWidget):
widget_state['value'] = widget.getValue()
widget_state['enabled'] = widget.isEnabled()
widget_state['visible'] = widget.isVisible()
widget_state['widget_row'] = self.getWidgetRow(name, role)
Expand Down Expand Up @@ -420,6 +423,9 @@ def applyWidgetState(self, name, state, role=None):
widget.setChecked(value)
elif isinstance(widget, (QtWidgets.QTextEdit, QtWidgets.QPlainTextEdit)):
widget.setPlainText(value)
elif isinstance(widget, UISliderLEditWidget) or isinstance(
widget, QtWidgets.QWidget):
widget.setValue(value)

def applyWidgetStates(self, states):
'''
Expand Down
6 changes: 4 additions & 2 deletions eqt/ui/UISliderLEditWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ class UISliderLEditWidget(QWidget):
step_size : float
scale_factor : float
'''
def __init__(self, minimum=0.0, maximum=1.0, step_size=1.0, scale_factor=1.0):
def __init__(self, minimum=0.0, maximum=1.0, step_size=1.0, scale_factor=1.0,
tick_interval=1.0):
QWidget.__init__(self)

self.minimum = minimum
self.maximum = maximum
self.scale_factor = scale_factor
self.step_size = step_size * self.scale_factor
self.tick_interval = tick_interval * self.scale_factor

# Configure the QSlider
self.slider = QSlider()
Expand All @@ -28,7 +30,7 @@ def __init__(self, minimum=0.0, maximum=1.0, step_size=1.0, scale_factor=1.0):
self.slider.setFocusPolicy(QtCore.Qt.StrongFocus)
self.slider.setTickPosition(QSlider.TicksBelow)
self.slider.setSingleStep(self.step_size)
self.slider.setTickInterval(self.maximum * 0.25)
self.slider.setTickInterval(self.tick_interval)

# Connect the QSlider to the QLineEdit
self.slider.sliderPressed.connect(self.updateLineEdit)
Expand Down
5 changes: 3 additions & 2 deletions eqt/ui/UISliderWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class UISliderWidget(QSlider):
scale_factor : float
'''
def __init__(self, line_edit, max_label, minimum=0.0, maximum=1.0, scale_factor=1.0,
step_size=1.0):
step_size=1.0, tick_interval=1.0):
QSlider.__init__(self)

self.line_edit = line_edit
Expand All @@ -28,14 +28,15 @@ def __init__(self, line_edit, max_label, minimum=0.0, maximum=1.0, scale_factor=
self.maximum = maximum
self.scale_factor = scale_factor
self.step_size = step_size * self.scale_factor
self.tick_interval = tick_interval * self.scale_factor

# Configure the QSlider
self.setRange(self.minimum, self.maximum)
self.setOrientation(QtCore.Qt.Horizontal)
self.setFocusPolicy(QtCore.Qt.StrongFocus)
self.setTickPosition(QSlider.TicksBelow)
self.setSingleStep(self.step_size)
self.setTickInterval(self.step_size)
self.setTickInterval(self.tick_interval)

# Connect the QSlider to the QLineEdit
self.sliderPressed.connect(self.updateLineEdit)
Expand Down
21 changes: 18 additions & 3 deletions examples/dialog_save_state_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from PySide2 import QtWidgets

from eqt.ui import FormDialog
from eqt.ui.UISliderLEditWidget import UISliderLEditWidget
from eqt.ui.UISliderWidget import UISliderWidget


Expand All @@ -27,18 +28,32 @@ def __init__(self, parent=None):
# ## Example on how to add elements to the
dialog.addWidget(QtWidgets.QLabel('test label'), 'Label: ', 'label')
dialog.addWidget(QtWidgets.QCheckBox('test checkbox'), 'CheckBox: ', 'checkBox')

combobox = QtWidgets.QComboBox()
combobox.addItems(['test1', 'test2'])
dialog.addWidget(combobox, 'ComboBox: ', 'comboBox')

dialog.addWidget(QtWidgets.QDoubleSpinBox(), 'DoubleSpinBox: ', 'doubleSpinBox')
dialog.addWidget(QtWidgets.QSpinBox(), 'SpinBox: ', 'spinBox')
dialog.addWidget(QtWidgets.QSlider(), 'Slider: ', 'slider')
dialog.addWidget(UISliderWidget(QtWidgets.QLabel()), 'UISliderWidget: ', 'uiSliderWidget')
dialog.addWidget(QtWidgets.QRadioButton('test 1'), 'RadioButton 1: ', 'radioButton')
dialog.addWidget(QtWidgets.QRadioButton('test 2'), 'RadioButton 2: ', 'radioButton')

line_edit = QtWidgets.QLineEdit()
max_label = QtWidgets.QLabel()
dialog.addWidget(
UISliderWidget(line_edit, max_label, minimum=0.0, maximum=100.0, scale_factor=10.0),
'UISliderWidget: ', 'uiSliderWidget')
dialog.addWidget(max_label, '', 'input_max_label1')
dialog.addWidget(line_edit, '', 'input_line_edit1')

dialog.addWidget(UISliderLEditWidget(minimum=0.0, maximum=100.0, scale_factor=10.0),
'UISliderLEditWidget:', 'uiSliderLEditWidget')

dialog.addWidget(QtWidgets.QRadioButton('test 1'), 'RadioButton 1: ', 'radioButton1')
dialog.addWidget(QtWidgets.QRadioButton('test 2'), 'RadioButton 2: ', 'radioButton2')
dialog.addWidget(QtWidgets.QTextEdit('test'), 'TextEdit: ', 'textEdit')
dialog.addWidget(QtWidgets.QPlainTextEdit('test'), 'PlainTextEdit: ', 'plainTextEdit')
dialog.addWidget(QtWidgets.QLineEdit('test'), 'LineEdit: ', 'lineEdit')

button = QtWidgets.QPushButton('test')
button.setCheckable(True)
dialog.addWidget(button, 'Button: ', 'button')
Expand Down

0 comments on commit 5c595bf

Please sign in to comment.