Search code examples
pythonqtqt3

QScrollView with no scrollbars


I'm trying to make a QScrollView with around 100 different labels and buttons. But after I add them, the scrollbars do not appear.

here is an example of the code I wrote:

self.btn = {}
self.scroll = QScrollView(self)
self.scroll.setGeometry(QRect(0,0,300,300))
self.scroll.enableClipper(True)
vp = self.scroll.viewport()

for i in range(0,100):
  self.btn[i] = QPushButton(vp)

for i in range(0,100):
  self.scroll.addChild(self.btn[i],1,50*i)

self.scroll.setVScrollBarMode(QScrollView.AlwaysOn) make the scrollbar appear but not to work.

The buttons get added to the QScrollView but I can't scroll down to see them all what am I doing wrong? I'm using qt3.


Solution

  • You don't add all your little items to the scrollview. You have to insert a single, large container (a QFrame derived class, for example) into the scrollview that contains all your smaller widgets.