New double slider editor

Occasionally I want a slider to control 2 values, such as defining a date range or clipping parameters. In the past, I would just create 2 sliders using the RangeEditor. It worked fine, but took up 20 or so pixels and didn’t really visually show the relationship between the 2 variables.

BoundsEditor screen shot

BoundsEditor screen shot

Qt and PyQt made it ridiculously easy to create the control I wanted. I started off transcoding the Qt QSlider C++ code into python, then added the second slider. In all, its about 180 lines of Python, less than 50 of it specific to the seconds slider.

I also wrapped this into a Traits editor, which can be found at enthought.traits.ui.qt.extra.bounds_editor.BoundsEditor

12 thoughts on “New double slider editor

  1. avatarBryce Hendrix

    Here is my test code, which also includes a button to increment the leftmost slider:

    from enthought.traits.api import HasTraits, Range, Int, Button, Float
    from enthought.traits.ui.api import View, Item
    from enthought.traits.ui.qt4.extra.bounds_editor import BoundsEditor

    class Foo(HasTraits):
    bounds = Range(10,20,value=15)
    incr_low = Button("incr_low")
    first = Float(10)

    traits_view = View(Item('bounds', editor=BoundsEditor(low_name='first', high=20)),

    def _incr_low_changed(self):
    self.first += 1

    def _first_changed(self, old, new):
    print "new low:", new


  2. avatarTurbo

    Hello! I love this widget and it’s exactly what I need, however I don’t know how to add it to my QtDesigner… I know this is a n00b question, could you please point me to some good reading on the subject? Thanx! 🙂

  3. avatarbryce


    I did implement a wx version as well, but its not nearly as nice. If I remember correctly its just 2 sliders, stacked vertically.

  4. avatarJohn Smith

    Thanks for your reply. I have done the two sliders stacked vertically also but as you have noted it really is cumbersome. Your single slider is elegant. I think I will probably try to “roll my own” then. Again thanks

    1. avatarBryce Hendrix

      John, I was thinking about why I had to stack them- I tried putting 2 sliders on top of each other, but I had problems getting events on the bottom slider. Maybe you can make one slider the parent of the other & Skip the event so the parent gets it?

      In any case, I recommend Qt if possible 🙂

  5. avatarvane

    Very interesting, but the widget itself is not very useful without valueChanged signals for the min/max/span


Leave a Reply

Your email address will not be published. Required fields are marked *

Please leave these two fields as-is:

Protected by Invisible Defender. Showed 403 to 100,955 bad guys.