Please explain how to work with QScrollArea. The designer did, but does not work. I did not find normal solutions on the Internet

  • one
    Well, ScrollArea is a widget-container for widgets, whose size is usually very large and that the window with them fit, add scroll bars (sliders). What is your problem? - gil9red

1 answer 1

QScrollArea is a widget container for widgets, whose size is usually very large and that the window with them fits, add scroll bars (sliders).

To place widgets in QScrollArea need not a layout (layout), but a widget, so it has a setWidget method.

For example, this code will create a large number of buttons:

 from PyQt5 import Qt app = Qt.QApplication([]) layout = Qt.QGridLayout() for i in range(10): for j in range(5): button = Qt.QPushButton('{}x{}'.format(i, j)) layout.addWidget(button, i, j) w = Qt.QWidget() w.setLayout(layout) mw = Qt.QScrollArea() mw.setWidget(w) mw.resize(200, 200) mw.show() app.exec() 

The window will look like this:

enter image description here

When you increase the window size, the sliders will disappear:

enter image description here


QScrollArea can resize widgets in it, stretch them. The widgetResizable property, which is False by default, is responsible for this.

If QScrollArea activates this property ( mw.setWidgetResizable(True) ), then the widgets in it will stretch:

enter image description here

  • it turns out, you need a layout? - Evilenzo
  • Added to the answer: Для помещения виджетов в QScrollArea нужен не layout` (layout), but a widget, so it has a setWidget method.` - gil9red am