QSlider stepping?

Richard Durr picture Richard Durr · Jan 28, 2011 · Viewed 11.9k times · Source

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?

Answer

armonge picture armonge · Jan 28, 2011

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_())