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

    @
    ui->scrollAreaWidgetContents->layout()->addWidget(checkbox);
    ui->scrollAreaWidgetContents->layout()->addWidget(ComboOperator);
    @
    But now i wanted to create one more scroll area programattically(without designer)
    I declared as below...
    @
    QScrollArea *sarea=new QScrollArea;
    sarea->layout()->addWidget(checkbox);
    sarea->layout()->addWidget(ComboOperator);
    @

    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"));
    sarea->setLayout(layout);@

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.