Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Qt Creator's Designer generates hidden QWidget for layout, and this behavior results in a QScrollArea problem
QtWS25 Last Chance

Qt Creator's Designer generates hidden QWidget for layout, and this behavior results in a QScrollArea problem

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
qt designerhidden widgetqscrollarealayout
5 Posts 2 Posters 590 Views
  • 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
    fokhagyma
    wrote on last edited by
    #1

    I observed that Qt Designer generates a hidden QWidget whenever a QLayout is added to a QWidget, and sets that hidden QWidget between the seemingly parent QWidget and the QLayout.
    And if I add a QLayout to a QScrollArea, then the object tree in the Designer looks like this:
    986b7be4-9b5a-4c2e-8eda-0d4faf3a5d47-image.png
    As shown in the image, a QVBoxLayout added to a QScrollArea's QWidget. I cannot add layout to scroll area directly, just to scroll area's widget, and no matters if I set scroll area as ancestor or not, the result is the same. Moreover, the widget of the scroll area cannot be deleted.
    The code snippet below (from ui_widget.h) shows the generated hidden QWidget (for the object tree shown above):

    scrollArea = new QScrollArea(horizontalLayoutWidget);
    scrollArea->setObjectName("scrollArea");
    scrollArea->setWidgetResizable(true);
    scrollAreaWidgetContents = new QWidget();
    scrollAreaWidgetContents->setObjectName("scrollAreaWidgetContents");
    scrollAreaWidgetContents->setGeometry(QRect(0, 0, 394, 597));
    verticalLayoutWidget = new QWidget(scrollAreaWidgetContents);
    verticalLayoutWidget->setObjectName("verticalLayoutWidget");
    verticalLayoutWidget->setGeometry(QRect(110, 150, 160, 80));
    verticalLayout = new QVBoxLayout(verticalLayoutWidget);
    verticalLayout->setObjectName("verticalLayout");
    verticalLayout->setContentsMargins(0, 0, 0, 0);
    scrollArea->setWidget(scrollAreaWidgetContents);
    

    As can be see, the hidden QWidget is that whose name is "verticalLayoutWidget", it is hidden because it isn't showed in the Designer's object tree.
    So instead of setting the "verticalLayout" directly to the "scrollAreaWidgetContents", the generated code set it to the "verticalLayoutWidget".
    And the problem with this solution is that the scroll area won't be scrollable if there are lots of widgets in it. I tested that if I connect the "verticalLayout" to the "scrollAreaWidgetContents" directly in the generated code (by modifying the generated code through code editor), then the scroll area will be scrollable.

    So I have no idea, how can a layout in a scroll area be scrollable with Qt Designer.

    1 Reply Last reply
    0
    • F fokhagyma

      Sorry, I forgot to mention the used versions:
      Qt Creator version: 11.0.3
      Qt version: 6.6

      M Offline
      M Offline
      mpergand
      wrote on last edited by mpergand
      #3

      Hi @fokhagyma

      You must set the scrollAreaWidgetContents layout with right click > layout > Vertical layout
      You can do that by clicking in the scrollArea in the designer,
      or by clicking in scrollArea in the tree object view panel.

      No need to create a second widget.

      F 1 Reply Last reply
      0
      • F Offline
        F Offline
        fokhagyma
        wrote on last edited by
        #2

        Sorry, I forgot to mention the used versions:
        Qt Creator version: 11.0.3
        Qt version: 6.6

        M 1 Reply Last reply
        0
        • F fokhagyma

          Sorry, I forgot to mention the used versions:
          Qt Creator version: 11.0.3
          Qt version: 6.6

          M Offline
          M Offline
          mpergand
          wrote on last edited by mpergand
          #3

          Hi @fokhagyma

          You must set the scrollAreaWidgetContents layout with right click > layout > Vertical layout
          You can do that by clicking in the scrollArea in the designer,
          or by clicking in scrollArea in the tree object view panel.

          No need to create a second widget.

          F 1 Reply Last reply
          0
          • M mpergand

            Hi @fokhagyma

            You must set the scrollAreaWidgetContents layout with right click > layout > Vertical layout
            You can do that by clicking in the scrollArea in the designer,
            or by clicking in scrollArea in the tree object view panel.

            No need to create a second widget.

            F Offline
            F Offline
            fokhagyma
            wrote on last edited by fokhagyma
            #4

            @mpergand Thank you very much.

            Yes, it works but only after I drag a widget into the scroll area (at empty scroll area the layout options are greyed out).

            M 1 Reply Last reply
            0
            • F fokhagyma has marked this topic as solved on
            • F fokhagyma

              @mpergand Thank you very much.

              Yes, it works but only after I drag a widget into the scroll area (at empty scroll area the layout options are greyed out).

              M Offline
              M Offline
              mpergand
              wrote on last edited by
              #5

              @fokhagyma
              QDesigner is not the best/fancy app in the world.

              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