[solved] QScrollArea with dynamic contents



  • Hi everybody,

    Someone can help me with these Fu***ing Layout !!

    @
    QVBoxLayout *vLay = new QVBoxLayout(ui->scrollAreaWidgetContents_positions);

    for(int i=0; i<_code.size() ;i++)
    {
    QHBoxLayout *hLay = new QHBoxLayout(ui->scrollAreaWidgetContents_positions);
    QLabel *lab = new QLabel(this);
    lab->setText(QString(tr("Position %1:").arg(i+1)));

       QLineEdit *le = new QLineEdit(this);
       le->setText(_code[i]);
    
       hLay->addWidget(lab);
       hLay->addWidget(le);
       vLay->addLayout(hLay);
       vLay->addSpacing(40);
    

    }
    @

    My widegets Label and LineEdit are not in my scroll area I don't understant anything with this layout.
    I placed a QScrollArea in my ui file which contain a scrollAreaContentwidet i try everything but no one works.

    Thx for your help


  • Lifetime Qt Champion

    Hi,

    QScrollArea is not meant to be used with layouts, you put a widget in it with setWidget. That widget might be a complex widget with a layout.

    See "there":http://qt-project.org/doc/qt-5/qscrollarea.html#details

    @
    QWidget *placeHolder = new QWidget;
    QVBoxLayout *vLay = new QVBoxLayout(placeHolder);
    ui->scrollAreaWidgetContents_positions->setWidget(palceHolder);
    for(int i=0; i<_code.size() ;i++)
    {
    QHBoxLayout *hLay = new QHBoxLayout;
    QLabel *lab = new QLabel;
    lab->setText(QString(tr("Position %1:").arg(i+1)));

       QLineEdit *le = new QLineEdit;
       le->setText(_code[i]);
    
       hLay->addWidget(lab);
       hLay->addWidget(le);
       vLay->addLayout(hLay);
       vLay->addSpacing(40);
    

    }@

    Also be aware that giving a layout a parent means that you want to set the layout to the parent. Which is not what you want to do with e.g. hLay.



  • Thanks for your reply.
    It works, I have try this before but my QWidget here placeHolder have lost the "stylesheet" defined in my mainWidget


  • Lifetime Qt Champion

    Without seeing the style sheet I can't tell what might have gone wrong



  • Hi,
    it's just the background "transparent". I fixed it thx for your explanation.


  • Lifetime Qt Champion

    You're welcome !

    Since it looks like you have everything working please update the thread title prepending [solved] so other forum users may know a solution has been found :)



  • Sorry . the Problem is "solved"


Log in to reply
 

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