pyapp-kit / superqt

Missing widgets and components for Qt-python
https://pyapp-kit.github.io/superqt/
BSD 3-Clause "New" or "Revised" License
210 stars 37 forks source link

feat: categorical slider [WIP] #256

Open tlambert03 opened 1 month ago

tlambert03 commented 1 month ago

This adds a new QCategoricalSlider and QLabeledCategoricalSlider, when you want a slider to select from a discrete set of objects (rather than numbers). Similar to a combobox I guess, but easier to change between all the values.

API still needs consideration

from qtpy.QtWidgets import QApplication

from superqt.sliders import QLabeledCategoricalSlider

app = QApplication([])
slider = QLabeledCategoricalSlider(
    categories=["dog", "cat", "elephant", "bird", "fish"]
)
slider.show()
slider.categoryChanged.connect(lambda category: print(category))
app.exec()

https://github.com/user-attachments/assets/43ab9ead-2282-45c2-b166-79975e37648a

edit: the label is now a combobox to allow two-way editing

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 69.53642% with 46 lines in your changes missing coverage. Please review.

Project coverage is 85.95%. Comparing base (952ac33) to head (bb2b79d).

Files with missing lines Patch % Lines
src/superqt/sliders/_categorical_slider.py 35.13% 24 Missing :warning:
src/superqt/sliders/_labeled.py 80.70% 22 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #256 +/- ## ========================================== - Coverage 87.09% 85.95% -1.15% ========================================== Files 46 47 +1 Lines 3433 3503 +70 ========================================== + Hits 2990 3011 +21 - Misses 443 492 +49 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

Czaki commented 1 month ago

Maybe also add an enum version of it?