Question

Dear Stacktoverflow, can you show me an example of how to use a QScrollBar? Thanks.

Was it helpful?

Solution

It will come down to you using the QScrollArea, it is a widget that implements showing something that is larger than the available space. You will not need to use QScrollBar directly. I don't have a PyQt example but there is a C++ example in the QT distribution it is called the "Image Viewer". The object hierarchy will still be the same

OTHER TIPS

>>> import sys
>>> from PyQt4 import QtCore, QtGui
>>> app = QtGui.QApplication(sys.argv)
>>> sb = QtGui.QScrollBar()
>>> sb.setMinimum(0)
>>> sb.setMaximum(100)
>>> def on_slider_moved(value): print "new slider position: %i" % (value, )
>>> sb.connect(sb, QtCore.SIGNAL("sliderMoved(int)"), on_slider_moved)
>>> sb.show()
>>> app.exec_()

Now, when you move the slider (you might have to resize the window), you'll see the slider position printed to the terminal as you the handle.

In the PyQT source code distribution, look at the file:

examples/widgets/sliders.pyw

Or there is a minimal example here (I guess I shouldn't copy paste because of potential copyright issues)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top