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. Widgets do not expand to fill the entire vertical space of the screen ?
QtWS25 Last Chance

Widgets do not expand to fill the entire vertical space of the screen ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtableviewqlistviewqscrollarea
8 Posts 3 Posters 5.1k 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.
  • R Offline
    R Offline
    R-P-H
    wrote on last edited by
    #1

    Hi, I have a QTableView, QListView, and QScrollArea. The layouts are shown below.

    For the QTableView it automatically grows vertically to the height of the available screen before scroll bars are shown.

    For QListView and QScrollArea however, they do not grow to the full vertical height of the screen before scroll bars are shown. I have tried setting the vertical size policy of almost all the parent layouts/widgets to Expanding, but it seems to make no difference.

    I don't understand why it's working for QTableView but not the others. I can't seem to find any pattern in the parent widgets that causes this?

    QT_Layouts.png

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

      Hi,

      Not knowing how you coded that prevents us from giving you good answer.

      Some observations:

      • putting a vertical layout in a form layout is not best idea. QFormLayout is designed to build forms
      • Stacking so many QFrame seems odd from a GUI perspective.
      • I would recommend building each complex tab of your tab widget as an independent widget. You will avoid creating a complex enormous single monster widget that will be a pain to maintain.

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

      R 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Not knowing how you coded that prevents us from giving you good answer.

        Some observations:

        • putting a vertical layout in a form layout is not best idea. QFormLayout is designed to build forms
        • Stacking so many QFrame seems odd from a GUI perspective.
        • I would recommend building each complex tab of your tab widget as an independent widget. You will avoid creating a complex enormous single monster widget that will be a pain to maintain.
        R Offline
        R Offline
        R-P-H
        wrote on last edited by
        #3

        @SGaist Thanks for the notes. With regards to the 2nd diagram, which is a bit more simple than the last, what code would you need to better understand the issue? It was designed using Qt Designer.

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

          The issue is that you seem to try to cobble stuff together and "let it work".

          I would recommend starting with just a pen and paper to visualise the UI you want and then start designer. Learn about Qt's layout classes and then build small thing one after the other using the minimal amount of building blocks.

          Personally I build UIs only in code because I am faster doing so and have a clearer picture of what goes where.

          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
          • C Offline
            C Offline
            ChrisW67
            wrote on last edited by
            #5

            The QScrollArea, your outermost widget, provides a view onto an internal widget of indeterminate size. The internal widget may be bigger, smaller, or the same size as the viewport the scroll area has to display it in. The QScrollArea does not resize the internal widget in any way, just displays some or all of it.

            The QTabWidget (blue one) you use as the scrollable widget will have either a "natural" size based on the constraints of the widgets it contains, or some sort of fixed size that you control. It is possible to wait until the scroll area is displayed, determine the size of the viewport, and resize the QTabWidget to match that. After that the tab widget will remain fixed in size and the scroll area will not have to produce scroll bars unless the QScrollArea widget is resized down.

            In the case of the table view, where the drawn table has more content than will fit on the screen (i.e. this widget is bigger than the viewport), the scroll area will display more of the underlying table as the view port grows until the screen size constrains the QScrollArea. Make your QTabWidget widget taller than the available screen height and you will see the same behaviour.

            R 1 Reply Last reply
            1
            • C ChrisW67

              The QScrollArea, your outermost widget, provides a view onto an internal widget of indeterminate size. The internal widget may be bigger, smaller, or the same size as the viewport the scroll area has to display it in. The QScrollArea does not resize the internal widget in any way, just displays some or all of it.

              The QTabWidget (blue one) you use as the scrollable widget will have either a "natural" size based on the constraints of the widgets it contains, or some sort of fixed size that you control. It is possible to wait until the scroll area is displayed, determine the size of the viewport, and resize the QTabWidget to match that. After that the tab widget will remain fixed in size and the scroll area will not have to produce scroll bars unless the QScrollArea widget is resized down.

              In the case of the table view, where the drawn table has more content than will fit on the screen (i.e. this widget is bigger than the viewport), the scroll area will display more of the underlying table as the view port grows until the screen size constrains the QScrollArea. Make your QTabWidget widget taller than the available screen height and you will see the same behaviour.

              R Offline
              R Offline
              R-P-H
              wrote on last edited by
              #6

              @ChrisW67 said in Widgets do not expand to fill the entire vertical space of the screen ?:

              The QScrollArea, your outermost widget, provides a view onto an internal widget of indeterminate size. The internal widget may be bigger, smaller, or the same size as the viewport the scroll area has to display it in. The QScrollArea does not resize the internal widget in any way, just displays some or all of it.

              The QTabWidget (blue one) you use as the scrollable widget will have either a "natural" size based on the constraints of the widgets it contains, or some sort of fixed size that you control. It is possible to wait until the scroll area is displayed, determine the size of the viewport, and resize the QTabWidget to match that. After that the tab widget will remain fixed in size and the scroll area will not have to produce scroll bars unless the QScrollArea widget is resized down.

              In the case of the table view, where the drawn table has more content than will fit on the screen (i.e. this widget is bigger than the viewport), the scroll area will display more of the underlying table as the view port grows until the screen size constrains the QScrollArea. Make your QTabWidget widget taller than the available screen height and you will see the same behaviour.

              Thank-you for the explanation. In the case of the 2nd diagram, the viewport is is obviously not taking up the full height of the screen then. The outer scrollArea has no scrollbars and is taking up half the screen height. The inner scrollArea has more content than what can be displayed thus creating inner scrollbars. I still am unsure as to how I can get the outer scrollArea to have a larger viewport up to the vertical height of the screen.

              C 1 Reply Last reply
              0
              • R R-P-H

                @ChrisW67 said in Widgets do not expand to fill the entire vertical space of the screen ?:

                The QScrollArea, your outermost widget, provides a view onto an internal widget of indeterminate size. The internal widget may be bigger, smaller, or the same size as the viewport the scroll area has to display it in. The QScrollArea does not resize the internal widget in any way, just displays some or all of it.

                The QTabWidget (blue one) you use as the scrollable widget will have either a "natural" size based on the constraints of the widgets it contains, or some sort of fixed size that you control. It is possible to wait until the scroll area is displayed, determine the size of the viewport, and resize the QTabWidget to match that. After that the tab widget will remain fixed in size and the scroll area will not have to produce scroll bars unless the QScrollArea widget is resized down.

                In the case of the table view, where the drawn table has more content than will fit on the screen (i.e. this widget is bigger than the viewport), the scroll area will display more of the underlying table as the view port grows until the screen size constrains the QScrollArea. Make your QTabWidget widget taller than the available screen height and you will see the same behaviour.

                Thank-you for the explanation. In the case of the 2nd diagram, the viewport is is obviously not taking up the full height of the screen then. The outer scrollArea has no scrollbars and is taking up half the screen height. The inner scrollArea has more content than what can be displayed thus creating inner scrollbars. I still am unsure as to how I can get the outer scrollArea to have a larger viewport up to the vertical height of the screen.

                C Offline
                C Offline
                ChrisW67
                wrote on last edited by ChrisW67
                #7

                @R-P-H The outermost QScrollArea size is driven by one of two things:

                • The layout that it is placed in if it is not a top-level widget.
                • The size you set if it is a top-level widget.

                I suspect you are in the second group. The top-level widget will adopt a default size based on its content and any constraints place on it by the window manager... it does not have to stay that way.
                It seems you want to call scrollArea->resize() to set the height to the screen height. You can get the screen dimensions something like:

                QScreen *screen = app->primaryScreen();
                scrollArea->resize(screen.availableGeometry().size());
                
                // or after Qt 5.14
                QScreen *screen = scrollArea->screen();
                scrollArea->resize(screen.availableGeometry().size());
                

                You may need to arrange this to happen after the widget is displayed by triggering it with a zero duration, single shot QTimer.

                R 1 Reply Last reply
                1
                • C ChrisW67

                  @R-P-H The outermost QScrollArea size is driven by one of two things:

                  • The layout that it is placed in if it is not a top-level widget.
                  • The size you set if it is a top-level widget.

                  I suspect you are in the second group. The top-level widget will adopt a default size based on its content and any constraints place on it by the window manager... it does not have to stay that way.
                  It seems you want to call scrollArea->resize() to set the height to the screen height. You can get the screen dimensions something like:

                  QScreen *screen = app->primaryScreen();
                  scrollArea->resize(screen.availableGeometry().size());
                  
                  // or after Qt 5.14
                  QScreen *screen = scrollArea->screen();
                  scrollArea->resize(screen.availableGeometry().size());
                  

                  You may need to arrange this to happen after the widget is displayed by triggering it with a zero duration, single shot QTimer.

                  R Offline
                  R Offline
                  R-P-H
                  wrote on last edited by
                  #8

                  @ChrisW67 Thanks ! The resizing works but screen.availableGeometry().size() is giving the incorrect size (much too big). I tried a variety of other ways but can't seem to get the correct available size even when running it after the widget is displayed using a timer as suggested.

                  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