Reputation: 21
I have created a GUI in Qt Designer with a horizontal slider inside a grid layout within a tab widget. Here is the code from the GUI.py file:
self.horizontalSlider = QtGui.QSlider(self.tab)
self.horizontalSlider.setOrientation(QtCore.Qt.Horizontal)
self.horizontalSlider.setObjectName(_fromUtf8("horizontalSlider"))
self.horizontalSlider.setRange(0.1,0.4)
self.horizontalSlider.setValue(0.4)
self.horizontalSlider.setTickInterval(0.05)
self.gridLayout_4.addWidget(self.horizontalSlider, 3, 1, 1, 1)
I have set up a connection for the release signal in my main code:
self.horizontalSlider.sliderReleased.connect(self.SmoothSelected)
At runtime, the slider remains at the start position and I am unable to move it. I tested its value with:
print(self.horizontalSlider.value())
but get '0', not '0.4' as I have set the value to be. The other widgets in the tab work fine. Have I forgotten something simple like enabling it or something?
Upvotes: 0
Views: 3388
Reputation: 1476
Documentation states:
The slider is the classic widget for controlling a bounded value. It lets the user move a slider handle along a horizontal or vertical groove and translates the handle's position into an integer value within the legal range.
Consequently, setRange
, setValue
and setTickInterval
accept only int as a argument. That is - you can only move slider by int values.
The workaround is either converting int value from QSlider
to float by multiplying it to .01 (or other value), or implementing your own QDoubleSlider
like in this gist.
Upvotes: 4