RE: Logarithmic scale on slider (PyQwt)
Brought to you by:
rathmann
|
From: Darryl W. <dar...@pr...> - 2010-07-28 21:05:32
|
Hello,
> -----Original Message-----
> From: Lieven Buts [mailto:lie...@gm...]
> Sent: July-28-10 4:51 AM
> To: qwt...@li...
> Subject: Logarithmic scale on slider (PyQwt)
>
> Hi all,
>
> I am experimenting with the Qwt controls using PyQwt 5.2.0. I adapted
the C++
> sliders example into this minimal Python script:
> ----------------------------
> #!/usr/bin/env python2.5
>
> import sys
> from PyQt4.QtGui import QApplication, QWidget, QHBoxLayout
> from PyQt4.QtCore import Qt, SIGNAL
> import PyQt4.Qwt5 as Qwt
>
> app = QApplication(sys.argv)
> mw = QWidget()
> layout = QHBoxLayout()
>
> s=Qwt.QwtSlider(mw, Qt.Horizontal, Qwt.QwtSlider.BottomScale)
> s.setScaleEngine(Qwt.QwtLog10ScaleEngine())
> s.setRange(1, 1.0e2)
> s.setScaleMaxMinor(10)
>
> def report(value):
> print "%10.3g" % value
>
> mw.connect(s, SIGNAL("valueChanged(double)"), report)
>
> layout.addWidget(s)
> mw.setLayout(layout)
> mw.show()
>
> sys.exit(app.exec_())
> ----------------------------
>
> The slider and its scale are displayed fine, but the values returned by
the
> valueChanged() signal correspond to a linear scale instead of a
logarithmic
> one. For instance, with the slider in the middle position, the signal
returns
> 50.5, instead of 10 as indicated on the scale. This happens on Mac OS X
> and Linux.
>
> Am I missing a method call, or is changing the ScaleEngine supposed to
> change the returned values as well?
Revisit the example (there's a python one for this as well -
SliderDemo.py). You're missing the use of setRange and setScale.
You're wanting
s.setRange(0,2,0.01) #The actual floating point range of the slider.
s.setScale(1,1.0e2) #The visible scale min/max.s
and when you print out the result, you want to print out 10**value.
It's up to you to map and transform the values yourself. The scaleEngine
doesn't do it for you.
Though, it would be nice if it could do it automatically., I spose.
Darryl
|