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. Scaling Layouts in Layouts (pls help)
Forum Updated to NodeBB v4.3 + New Features

Scaling Layouts in Layouts (pls help)

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 318 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.
  • J Offline
    J Offline
    jpie
    wrote on last edited by
    #1

    I have a main window with a vertical layout and inside it are two horizontal sub layouts. So the window is split into two horizontal layouts aligned vertically. Is there an intuitive way to make one layout take up more of the screen, like a stretch factor? It seems like a trivial thing but I haven't found a way.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on last edited by
      #2

      Hi, are you using ui files or are you doing in the cpp files?
      If you're using ui files, you can look at this post:
      https://forum.qt.io/topic/114009/how-to-set-different-size-of-layouts-in-qt

      If you are doing in the cpp files, you should look at:

      void QBoxLayout::setStretch(int index, int stretch)
      

      or

      void QBoxLayout::addLayout(QLayout *layout, int stretch = 0)
      
      J 1 Reply Last reply
      3
      • B Bonnie

        Hi, are you using ui files or are you doing in the cpp files?
        If you're using ui files, you can look at this post:
        https://forum.qt.io/topic/114009/how-to-set-different-size-of-layouts-in-qt

        If you are doing in the cpp files, you should look at:

        void QBoxLayout::setStretch(int index, int stretch)
        

        or

        void QBoxLayout::addLayout(QLayout *layout, int stretch = 0)
        
        J Offline
        J Offline
        jpie
        wrote on last edited by jpie
        #3

        @Bonnie Thank you so much for this amazing answer. If I assign a layout to the central widget, is it possible to use a layout stretch? Or do I have to make a new layout within it first? Also, is there a way to do this with a splitter?

        B 1 Reply Last reply
        0
        • J jpie

          @Bonnie Thank you so much for this amazing answer. If I assign a layout to the central widget, is it possible to use a layout stretch? Or do I have to make a new layout within it first? Also, is there a way to do this with a splitter?

          B Offline
          B Offline
          Bonnie
          wrote on last edited by Bonnie
          #4

          @jpie You can use a layout stretch as long as it is a box layout or grid layout.
          And yes, QSplitter also has a similar function:

          void QSplitter::setStretchFactor(int index, int stretch)
          

          Since it actually does is setting the stretch of the widget's size policy, if you want to do it in the ui file, you can just set the HorizontalStretch / VerticalStretch of the sizePolicy in a splitter's child widget.

          1 Reply Last reply
          3

          • Login

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