There is a QScrollArea . In it you need to shove the n-th number of widgets so that everything is scrolled when in need. I tried to shove the layout using setLayout() . Widgets are thrust into it, but not scrolled. As far as I understand, a widget should be placed there, inside which you can already insert the same layout . Is it that way or can it be made more elegantly?

My suggestion:

 QScrollArea scroll = new QScrollArea; QWidget* widget = new QWidget; QVBoxLayout* inside = new QVBoxLayout; widget->setLayout(inside); scroll->setWidget(widget); 

    1 answer 1

    It must be something like this:

      QScrollArea* scroll = new QScrollArea; QWidget* ScrollAreaWidgetContents = new QWidget(scroll); QGridLayout* ScrollLayout = new QGridLayout(ScrollAreaWidgetContents); QWidget* widget = new QWidget; ScrollLayout ->addWidget(widget); 

    And it is desirable to replace the first line with

      QScrollArea* scroll = new QScrollArea(this); 

    unless, of course, this points to a widget. I assume that in this case you have this will be a QMainWindow. The bottom line is that Qt monitors memory freeing, but only if the element has a parent

    • And if the widget is added by the addWidget() method, then, in theory, will Qt also assign a widget to this parent? - sm4ll_3gg
    • According to QtAssistant, addWidget () uses the addItem () function, and the description of addItem () specifies: That is, the widget goes under the control of the layout, and now the removal of the widget is the responsibility of this layout - Matty
    • Strange, but he still does not scroll imgur.com/cwYBvqN . Here's the pastebin.com/G3GMTAG6 code - sm4ll_3gg
    • And what exactly should it scroll? the inscription takes one line. Try inserting long text, for example. In order for the text inside the label not to leave infinitely sideways, but to be transferred, it is necessary for it to set setWordWrap (true). And you probably also need to set the maximum size of the main widget, if not specified. And if that widget was an example. If you don't need him, then there is no point in it) - Matty