我想发送带有qt horizontalSlider的浮点值“step”,我正在尝试这样做,但它不起作用:
horizontalSlider.setRange(0,25)
horizontalSlider.setSingleStep(horizontalSlider.maximum()/100.0)
horizontalSlider.valueChanged.connect(self.valueHandler)
然后我在这里得到了值(value):
def valueHandler(self,value):
print value
但是,但是,Im得到的输出是1,2,3,4,5,6,7,8......。
最佳答案
由于您希望单步为25/100 = 0.25,因此您应该这样做:
horizontalSlider.setRange(0,100)
horizontalSlider.setSingleStep(1)
horizontalSlider.valueChanged.connect(self.valueHandler)
def valueHandler(self,value):
scaledValue = float(value)/4 #type of "value" is int so you need to convert it to float in order to get float type for "scaledValue"
print scaledValue , type(scaledValue)
关于python - Qt horizontalSlider发送浮点值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20632841/