0

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.

Matteo Alessani
  • 10,264
  • 4
  • 40
  • 57
Urban48
  • 1,398
  • 1
  • 13
  • 26

2 Answers2

1

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.

Brian Roach
  • 76,169
  • 12
  • 136
  • 161
0

Actually you just need to give the scroll-view a layout and add your widgets to this. Adding them as sub-widgets of one big widget within the scrollview will do this for you, but it's messier.

theheadofabroom
  • 20,639
  • 5
  • 33
  • 65