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
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
Where exactly could I see the implementation ? Thks
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)),
Item('incr_low'))
def _incr_low_changed(self):
self.first += 1
def _first_changed(self, old, new):
print "new low:", new
Foo().configure_traits()
of course, wordpress screwed up the formatting of my code, so beware…
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!
I no next to nothing about QtDesigner. You’ll probably need to look at the BoundsEditor source and strip out the control, then follow the instructions on Riverbank’s website
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/pyqt4ref.html#writing-qt-designer-plugins
Thanks for the demo. It presents a really nice way to implement a double slider. We need the similar widget in our program and I made my own version in C++ with Qt4. A recorded video was uploaded to http://www.youtube.com/watch?v=zHIyUd6Q28U
Hi Bryce. Do you have something similair using wxPython?
I misspelled the e-mail address sorry
John,
I did implement a wx version as well, but its not nearly as nice. If I remember correctly its just 2 sliders, stacked vertically.
Bryce,
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
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
Very interesting, but the widget itself is not very useful without valueChanged signals for the min/max/span