Skip to content

Commit

Permalink
Add QLabel to UISliderWidget to display max slider value
Browse files Browse the repository at this point in the history
  • Loading branch information
jcornall committed Dec 20, 2024
1 parent e93a971 commit a375e9b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions eqt/ui/UISliderLEditWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def __init__(self, minimum=0.0, maximum=1.0, step_size=1.0, scale_factor=1.0):

# Connect the QLineEdit to the QSlider
self.line_edit.textEdited.connect(self.update_slider)
self.line_edit.returnPressed.connect(self.update_slider)

# Configure the min/max QLabels
self.min_label = QLabel()
Expand Down
18 changes: 10 additions & 8 deletions eqt/ui/UISliderWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ class UISliderWidget(QSlider):
'''Creates a Slider widget which updates
a QLineEdit with its value (which may be scaled
to a non-integer value by setting the scale_factor)
Also accepts a QLabel that is configured to
display the maximum value of the QSlider
Parameters
----------
line_edit : QLineEdit
min_label : QLabel
max_label : QLabel
minimum : float
maximum : float
step_size : float
scale_factor : float
'''
def __init__(self, line_edit, min_label, max_label, minimum=0.0, maximum=1.0, scale_factor=1.0,
def __init__(self, line_edit, max_label, minimum=0.0, maximum=1.0, scale_factor=1.0,
step_size=1.0):
QSlider.__init__(self)

self.line_edit = line_edit
self.min_label = min_label
self.max_label = max_label
self.minimum = minimum
self.maximum = maximum
Expand Down Expand Up @@ -50,15 +50,17 @@ def __init__(self, line_edit, min_label, max_label, minimum=0.0, maximum=1.0, sc
self.validator.setLocale(QtCore.QLocale("en_US"))

self.line_edit.setValidator(self.validator)
self.line_edit.setText(str(minimum))
self.line_edit.setPlaceholderText(str(minimum))
self.line_edit.setText(str(self.minimum))
self.line_edit.setPlaceholderText(str(self.minimum))

# Connect the QLineEdit to the QSlider
self.line_edit.textEdited.connect(self.update_slider)
self.line_edit.returnPressed.connect(self.update_slider)

# Configure QLabels for minimum and maximum QSlider values
# self.min_label = min_label
# self.max_label = max_label
# Configure QLabel to show maximum QSlider value
self.max_label = max_label
self.max_label.setAlignment(QtCore.Qt.AlignRight)
self.max_label.setText(str(self.maximum))

def get_slider_value(self):
return self.value()
Expand Down
9 changes: 5 additions & 4 deletions examples/dialog_example_uislider.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ def openFormDialog(self):
# Example on how to add elements to the FormDialog
# add input 1 as UISliderWidget and QLineEdit
line_edit = QtWidgets.QLineEdit()
min_label = QtWidgets.QLabel()
max_label = QtWidgets.QLabel()
uislider = UISliderWidget.UISliderWidget(line_edit, min_label, max_label, minimum=0.0,
maximum=10.0)
uislider = UISliderWidget.UISliderWidget(line_edit, max_label, minimum=0.0, maximum=100.0,
step_size=1.0)

# add to the form widget
dialog.addWidget(uislider, 'QSlider 1:', 'input_slider1')
dialog.addWidget(max_label, '', 'input_max_label1')
dialog.addWidget(line_edit, '', 'input_line_edit1')

# add input 2 as UISliderLineEditWidget
uislider = UISliderLEditWidget.UISliderLEditWidget(minimum=0.0, maximum=10.0,
uislider = UISliderLEditWidget.UISliderLEditWidget(minimum=0.0, maximum=100.0,
step_size=1.0)

# add to the form widget
Expand All @@ -53,6 +53,7 @@ def openFormDialog(self):
def accepted(self):
print("accepted")
print(f"QSlider 1 Value: {self.dialog.widgets['input_slider1_field'].value()}")
print(f"QLabel 1 Value: {self.dialog.widgets['input_max_label1_field'].text()}")
print(f"QLineEdit 1 Value: {self.dialog.widgets['input_line_edit1_field'].text()}")

# print(f"QSlider 2 Value: {self.dialog.widgets['input_slider2_field'].value()}")
Expand Down

0 comments on commit a375e9b

Please sign in to comment.