[Solved] Scroll Area



  • can i put a layout into a scroll area. cuz when i did tht i could get any scroll bars. I have a series of labels put into layouts. I have tried to put the layout into the scrollarea.

    It doesn work. Any other alternative?? Shouldi put the labels directly on to the scroll area

    Thanks

    alfah



  • Yes, but you need to put the layout on QScrollArea::widget(), not on the QScrollArea itself.



  • andre

    @
    QScrollArea *scrollarea = new QScrollArea();

    controlLayout=new QVBoxLayout;
    controlLayoutSec=new QVBoxLayout;
    controlLayout->addWidget(lblBlnk);
    controlLayoutSec->addWidget(lblBlnk);
    
    
    
    hLayout3->addLayout(controlLayout);
    hLayout3->addSpacing(50);
    hLayout3->addLayout(controlLayoutSec);
    
    scrollarea->setWidget(hLayout3);
    

    @

    I have done somethin like tht but the scrol bars do not appear



  • hLayout3 is not a widget, but a layout. Instead, do something like this:

    @
    scrollArea->widget()->setLayout(hLayout3);
    @



  • andre

    the following line jus aborted prograrm
    @
    scrollarea->widget()->setLayout(hLayout3);
    @

    is it addwidget???



  • Perhaps widget() returns 0, and you need to create such a widget first yourself.
    Try:
    @
    QWidget* baseArea = new QWidget(0);
    baseArea->setLayout(hLayout3);
    scrollArea->setWidget(baseArea);
    @



  • I have written the following two lines too
    @

    QHBoxLayout *hLayoutScrollArea = new QHBoxLayout;
    hLayoutScrollArea->addWidget(scrollarea);

    @



  • That will put the scroll area itself in a layout, but without something like this, will not do anything:

    @
    theParentWidgetOfYourScrollArea->setLayout(hLayoutScrollArea);
    @



  • i got the program runnin but no widgets are displayed!!!!
    @
    QHBoxLayout *hLayout3 = new QHBoxLayout;
    QLabel *lblBlnk =new QLabel();

    QScrollArea *scrollarea =  new QScrollArea();
    
    
    controlLayout=new QVBoxLayout;
    controlLayoutSec=new QVBoxLayout;
    controlLayout->addWidget(lblBlnk);
    controlLayoutSec->addWidget(lblBlnk);
    
    
    
    hLayout3->addLayout(controlLayout);
    hLayout3->addSpacing(50);
    hLayout3->addLayout(controlLayoutSec);
    
    QWidget *baseArea = new QWidget();
    baseArea->setLayout(hLayout3);
    scrollarea->setWidget(baseArea);
    
    
    scrollarea->widget()->setLayout(hLayout3);
    
    
    QHBoxLayout *hLayoutScrollArea = new QHBoxLayout;
    hLayoutScrollArea->addWidget(scrollarea);
    
    
    secondLbl =new QLabel();
    secondLbl->setText(" ");
    
    vLayout=new QVBoxLayout;
    vLayout->addWidget(lblHeader);
    vLayout->addSpacing(50);
    vLayout->addLayout(hLayout1);
    vLayout->addWidget(lblTitle2);
    vLayout->addLayout(hLayout2);
    vLayout->addLayout(hLayoutScrollArea);
    vLayout->addWidget(secondLbl);
    

    @



  • Found tht something is displayed, but its not legible.

    I have put the scroll area into another layout. and finally all the layouts are put into one single vLayout.
    I have done this so as to display in another class containing tabs, so the final vLayout goes into the another widget and then displayed on tabs



  • Make sure that the top level layout (there can be only one!) is actually set on the top level widget. Otherwise, your dialog will not properly layout at all.



  • the thing is, every other widget in the form, other than the scrollares is displayed. Its the jus the scrollarea which is messed up



  • could u tell me how to include an image, i'l show a diagram to explain better what im tryin to do


  • Moderators



  • :D i got it right. It was jus that the widgets were not stretched. There is a property called setWidgetResizable(true) which automatically adjusts the size of widgets. :)

    solution:
    after you create a scroll area jus add the following line
    @
    scrollarea->setWidgetResizable(true);
    @

    Au Revoir :D

    alfah


Log in to reply
 

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