Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] QScrollArea with dynamic contents

[solved] QScrollArea with dynamic contents

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 3.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Francknos
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Francknos
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • F Offline
            F Offline
            Francknos
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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 :)

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • F Offline
                F Offline
                Francknos
                wrote on last edited by
                #7

                Sorry . the Problem is "solved"

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved