Search code examples
pythonqtpyqtqsliderqabstractslider

QSlider stepping?


I'd like to specify the steps that a QSlider can slide, like it is possible for the QSpinBox by using setSingleStep. I tried to use setSingleStep of QAbstractSlider, but this seems to have no effect.

Any ideas?


Solution

  • Try setting the tickInterval

    EDIT

    Sorry for the tickInterval, didn't quite thinked about it, however i have this working code and it does what you want using setSingleStep

    import sys
    from PyQt4.QtGui import QApplication, QSlider, QMainWindow
    
    class Window(QMainWindow):
        def __init__(self, parent = None):
            super(Window, self).__init__(parent)
    
            slider = QSlider()
            slider.setMinimum(0)
            slider.setMaximum(100)
    
            slider.setTickInterval(20)
            slider.setSingleStep(20)
    
    
            self.setCentralWidget(slider)
    
    
    if __name__ == "__main__":
        app = QApplication(sys.argv)
    
        window = Window()
        window.show()
    
        sys.exit(app.exec_())