Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QT Designer - Slider with decimal steps



  • Hi all, new here. I am starting with Qt5 and building a control interface based on sliders, doublespinbox and LCDs

    I cannot find a way in QT Designer to set a slider with decimal steps, I will be working with temp and pressure so decimals are mandatory.

    Double spinbox works for that but I would like to have decimals also for sliders. Is this feasible from QT Designer? currently using v 5.15.2

    Thanks in advance

    Franco


  • Lifetime Qt Champion

    Hi and welcome to the forums

    Im afraid the slider cannot do decimal steps so you are most likely looking at a custom slider
    to make that happen.
    I could not find an example of decimal steps, only using doubles for its value but could be a starting point
    https://stackoverflow.com/questions/19003369/how-to-make-a-qslider-change-with-double-values



  • THanks for the hint, will work on that

    regards

    Franco



  • At the end I found easier to keep the SLider generated by QT Designer and connect to a simple function scaling the values, like this:

    tempSlider = temperature slider
    tempSpinBox= double Spin Box for temperature

    from slider to spinbox

    self.tempSlider.valueChanged['int'].connect(self.changeTspinBoxValue)

    def changeTspinBoxValue(self,val):
    val = float(val / 10)
    print(val)
    self.tempSpinBox.setValue(val)

    and viceversa for spinbox to slider

    self.tempSpinBox.valueChanged['double'].connect(self.changeTsliderValue)

    def changeTspinBoxValue(self,val):
    val = float(val / 10)
    print(val)
    self.tempSpinBox.setValue(val)

    Thanks


Log in to reply