Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add QLineEdit support to UISliderWidget #168

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open

Conversation

jcornall
Copy link
Collaborator

@jcornall jcornall commented Dec 16, 2024

Closes #125 #60

The current UISliderWidget is limited due to the following factors:

  • Instantiating a UISliderWidget requires a QLabel, which is updated to show the value of the slider
  • The QLabel cannot be updated manually
  • The slider does not support float/double values

This pull request originally removed the QLabel parameter in favour of a QDoubleSpinBox parameter. It was decided that to provide the best user experience and enable flexibility to modify the widget in the future, more changes would be required:

  • The UISliderWidget class now inherits from the QWidget class, instead of QSlider
  • The class now creates a QGridLayout, which ensures future flexibility in modifying/customising the arrangement of the subwidgets within the UISliderWidget
  • Instead of a QDoubleSpinBox, a QLineEdit has been added so that users can fine-tune the widget's value
  • New QLabels have been added to display the minimum, median and maximum values of the widget
  • Validation (QValidator and conditional checks) has been added to ensure arguments and user inputs are valid, alongside behaviour to handle invalid inputs
  • Parameterized unit tests have been added, testing the UISliderWidget specifically, see test_UISliderWidget.py
  • Existing examples in the /examples/ folder have been updated to accommodate the updated UISliderWidget
  • Docstrings have been added to the UISliderWidget class, the tests, and the example
  • Calls to the UISliderWidget class have been updated elsewhere in eqt in line with the changes made

PLEASE NOTE: By default the QSlider.value() method only returns integer values - even if the value of the QLineEdit is a float/double, this value is automatically converted to an integer when the QSlider value is updated. Additional methods have been implemented to convert the QSlider value into a scaled QLineEdit value, and vice versa. This means the QSlider can now accurately represent float/double values.

Current Tasks:

  • Implement QLineEdit
  • Remove hardcoded values
  • Make sure spinbox is linked to slider
  • Overload the init, one with the DSpinBox and one without
  • Add min and max QLabels
  • Consider whether to split the class into two separate classes
  • Add tests for the widget to eqt

@jcornall jcornall added this to the Version x.x.x milestone Dec 16, 2024
@jcornall jcornall requested a review from DanicaSTFC December 16, 2024 16:28
@jcornall jcornall self-assigned this Dec 16, 2024
eqt/ui/UISliderWidget.py Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@jcornall jcornall changed the title Add QDoubleSpinBox support to UISliderWidget Add QLineEdit support to UISliderWidget Dec 19, 2024
@jcornall
Copy link
Collaborator Author

Updated PR title to reflect changes to the design of the UISliderWidget class.

Following discussions with @paskino and @DanicaSTFC, it was agreed that instead of a QDoubleSpinBox the UISliderWidget class would make better use of a QLineEdit, removing restrictions on the decimal values users can input.

@jcornall
Copy link
Collaborator Author

image

QSlider 1: Modified UISliderWidget, individual widgets passed as arguments to connect them to the QSlider, then added to the FormDialog afterwards.
QSlider 2: New class UISliderLEditWidget, which creates its own widgets and adds them to a layout for display.

@jcornall
Copy link
Collaborator Author

jcornall commented Jan 9, 2025

QSlider and QLineEdit values scale accordingly using the _scaleUp() and _scaleDown() methods. The min/max values for the QSlider and QLineEdit are correctly mapped and have been tested with different inputs (negative values, decimal values, etc.)

image

@jcornall jcornall marked this pull request as ready for review January 17, 2025 15:39
@jcornall
Copy link
Collaborator Author

jcornall commented Jan 17, 2025

Need to clarify whether an empty QLineEdit should remain blank (None type) or if it should default to the minimum value in the range (could add it as an option).

@jcornall jcornall requested a review from DanicaSTFC January 17, 2025 16:33
eqt/ui/UIFormWidget.py Outdated Show resolved Hide resolved
eqt/ui/UIFormWidget.py Outdated Show resolved Hide resolved
eqt/ui/UIFormWidget.py Outdated Show resolved Hide resolved
eqt/ui/UISliderWidget.py Outdated Show resolved Hide resolved
eqt/ui/UISliderWidget.py Outdated Show resolved Hide resolved
eqt/ui/UISliderWidget.py Outdated Show resolved Hide resolved
eqt/ui/UISliderWidget.py Outdated Show resolved Hide resolved
eqt/ui/UISliderWidget.py Outdated Show resolved Hide resolved
eqt/ui/UISliderWidget.py Outdated Show resolved Hide resolved
eqt/ui/UISliderWidget.py Outdated Show resolved Hide resolved
examples/dialog_example_uislider.py Show resolved Hide resolved
examples/dialog_example_uislider.py Show resolved Hide resolved
examples/dialog_example_uislider.py Show resolved Hide resolved
examples/dialog_example_uislider.py Show resolved Hide resolved
examples/dialog_example_uislider.py Outdated Show resolved Hide resolved
@@ -6,3 +6,4 @@ dependencies:
- pip
- qtpy
- qdarkstyle
- parameterized
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this or is it only optional for the developer environment? Isn't it enough to add it to the pyproject? I am not sure

CHANGELOG.md Show resolved Hide resolved
test/test_UISliderWidget.py Show resolved Hide resolved
test/test_UISliderWidget.py Show resolved Hide resolved
test/test_UISliderWidget.py Outdated Show resolved Hide resolved
test/test_UISliderWidget.py Show resolved Hide resolved
test/test_UISliderWidget.py Show resolved Hide resolved
test/test_UISliderWidget.py Outdated Show resolved Hide resolved
test/test_UISliderWidget.py Show resolved Hide resolved
test/test_UISliderWidget.py Show resolved Hide resolved
test/test_UISliderWidget.py Show resolved Hide resolved
test/test_UISliderWidget.py Show resolved Hide resolved
@@ -0,0 +1,295 @@
import unittest

from parameterized import parameterized
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to add this in the developer requirements, and conda actions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UISliderWidget to have a QDoubleSpinBox attached
3 participants