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. Help with ScrollArea
Qt 6.11 is out! See what's new in the release blog

Help with ScrollArea

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.6k 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.
  • lonnieL Offline
    lonnieL Offline
    lonnie
    wrote on last edited by
    #1

    I am back again, and so close to having it working properly.

    I am creating a QFrame with a QFormLayout and I dynamically add labels and edit fields . It works well until I try and add more than will fit, at which time it increases my MainWindow height. This is OK unless someone attempts to have a form that exceeds to available screen height.

    In my quest to make it scrollable, like the QTreeWidget I am close but no prize. If I add more nodes to the QTreeWidget it simply creates a scrollbar and does the "right thing".

    With the QForm it expands the Mainwindow.

    QFrame * formFrame = new QFrame ();
    QFormLayout* layout = new QFormLayout(formFrame);
    formFrame->setLayout(layout);

    I have this code for the ScrollArea attempt, where it attempts to make the excess rows fit by squishing everything. No scrollbars appear.

    QFrame* formFrame = new QFrame();
    QScrollArea* ScrollArea = new QScrollArea(formFrame);
    ScrollArea->setWidgetResizable (true);
    ScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    ScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    QFormLayout* layout = new QFormLayout(ScrollArea);

    Here are some pictures of the simple
    0_1505523004897_NoScrollArea.png
    and using ScrollArea
    0_1505523041017_WithScrollArea.png

    kshegunovK 1 Reply Last reply
    0
    • kshegunovK kshegunov
      QWidget * container = new QWidget();
      QFormLayout * layout = new QFormLayout(container);
      // ... fill up the layout
      
      scrollArea->setWidget(container); //< Must be after the layout's been added to the container widget
      

      Here's a complete example.

      lonnieL Offline
      lonnieL Offline
      lonnie
      wrote on last edited by
      #3

      @kshegunov Yes, sir it works.

      I had 2 things wrong. I was setting the ScrollArea into the layout, That needs to be the form, ie formFrame and I needed to set the ScrollArea widget after I put all of my data into the layout.

      QFrame* formFrame = new QFrame();

      QScrollArea* ScrollArea = new QScrollArea(); //formFrame);
      ScrollArea->setWidgetResizable (true);
      ScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
      ScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);

      QFormLayout* layout = new QFormLayout(formFrame);

      // a whole bunch of statements that fill a label and text box and
      // put them to the layout as a row.
      // then this bit of magic

      ScrollArea->setWidget(formFrame);

      And the result is this
      0_1505530549751_WorkingScroll.png

      Thank you SO VERY MUCH. I spent a few days going forward and backward and sometimes sideways for a change.

      1 Reply Last reply
      0
      • lonnieL lonnie

        I am back again, and so close to having it working properly.

        I am creating a QFrame with a QFormLayout and I dynamically add labels and edit fields . It works well until I try and add more than will fit, at which time it increases my MainWindow height. This is OK unless someone attempts to have a form that exceeds to available screen height.

        In my quest to make it scrollable, like the QTreeWidget I am close but no prize. If I add more nodes to the QTreeWidget it simply creates a scrollbar and does the "right thing".

        With the QForm it expands the Mainwindow.

        QFrame * formFrame = new QFrame ();
        QFormLayout* layout = new QFormLayout(formFrame);
        formFrame->setLayout(layout);

        I have this code for the ScrollArea attempt, where it attempts to make the excess rows fit by squishing everything. No scrollbars appear.

        QFrame* formFrame = new QFrame();
        QScrollArea* ScrollArea = new QScrollArea(formFrame);
        ScrollArea->setWidgetResizable (true);
        ScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        ScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        QFormLayout* layout = new QFormLayout(ScrollArea);

        Here are some pictures of the simple
        0_1505523004897_NoScrollArea.png
        and using ScrollArea
        0_1505523041017_WithScrollArea.png

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by kshegunov
        #2
        QWidget * container = new QWidget();
        QFormLayout * layout = new QFormLayout(container);
        // ... fill up the layout
        
        scrollArea->setWidget(container); //< Must be after the layout's been added to the container widget
        

        Here's a complete example.

        Read and abide by the Qt Code of Conduct

        lonnieL 1 Reply Last reply
        2
        • kshegunovK kshegunov
          QWidget * container = new QWidget();
          QFormLayout * layout = new QFormLayout(container);
          // ... fill up the layout
          
          scrollArea->setWidget(container); //< Must be after the layout's been added to the container widget
          

          Here's a complete example.

          lonnieL Offline
          lonnieL Offline
          lonnie
          wrote on last edited by
          #3

          @kshegunov Yes, sir it works.

          I had 2 things wrong. I was setting the ScrollArea into the layout, That needs to be the form, ie formFrame and I needed to set the ScrollArea widget after I put all of my data into the layout.

          QFrame* formFrame = new QFrame();

          QScrollArea* ScrollArea = new QScrollArea(); //formFrame);
          ScrollArea->setWidgetResizable (true);
          ScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
          ScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);

          QFormLayout* layout = new QFormLayout(formFrame);

          // a whole bunch of statements that fill a label and text box and
          // put them to the layout as a row.
          // then this bit of magic

          ScrollArea->setWidget(formFrame);

          And the result is this
          0_1505530549751_WorkingScroll.png

          Thank you SO VERY MUCH. I spent a few days going forward and backward and sometimes sideways for a change.

          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