Dear Stacktoverflow, can you show me an example of how to use a QScrollBar? Thanks.
+1
A:
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
Harald Scheirich
2008-09-26 12:18:12
Harald, thanks for the reply. I tried the QScrollArea, which seems simpler in my case. But I have a QFormLayout to put inside that QScrollArea, and this widget accepts only QWidgets. I created an empty QWidget around the QFormLayout, but then nothing is displayed.
Victor Noagbodji
2008-09-26 13:19:34
Test the widget that you created with the layout first without the surrounding scroll area, if that displays correctly you will need to delve into the QScrollArea documentation, IMHO it is one of the more hairy parts of QT. In general a layout is not a widget, it is only formatting for the widget
Harald Scheirich
2008-09-26 13:23:36
+1
A:
>>> 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.
Torsten Marek
2008-09-26 12:28:38