Important: Please read the Qt Code of Conduct -

ScrollAreaWidgetContents not available when scroll area declared in code

  • I used scrollArea widget before, that time i created it in designer and to add the widgets into it i did as below

    But now i wanted to create one more scroll area programattically(without designer)
    I declared as below...
    QScrollArea *sarea=new QScrollArea;

    And when i tried to put inside it, program was crashing.
    Here i didnt get option to use scrollAreaWidgetContents, as it was available in designer....
    Please tell me what wrong here...

  • Hi. It's because QScrollArea didn't have layout by default. You must set it by yourself.
    Like this:
    @QScrollArea *sarea = new QScrollArea();
    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(new QPushButton("Hi"));

    So, program is crashed because you trying to use uncreated pointer.

Log in to reply