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. QWidget size policy and QMainWindow size, frames and layouts
Forum Updated to NodeBB v4.3 + New Features

QWidget size policy and QMainWindow size, frames and layouts

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 13.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.
  • 1 Offline
    1 Offline
    1231
    wrote on last edited by
    #1

    Hello,

    in a default Qt Desktop application, I set the size policy of the centralWidget to expanding, hoping it would expand to the QMainWindow size. It does not. How can I achieve such expansion?

    Also, layouts take care of their items sizes according to the size policies. A layout does not resize itself according to its items size, or do they? I put a layout inside a QFrame and sized the QFrame hoping the layout takes all the space inside the frame. The QFrame has its size policy set to minimum and its minimum size set to my target size.

    Am I tackling this task right or is a different approach meant to be taken in Qt?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      You are looking at this bottom-up. Widgets and layouts work from top to bottom, going through parent-child hierarchy.

      In order to make your central widget work as you wish, right click on it in Qt Creator (Qt Designer) and select a desired layout from "Lay out" submenu.

      (Z(:^

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

        The central widget doesn't have a Layout submenu. The QMainWindow has though. Its options "arrange vertically, arrange horizontally, ..." don't appear useful to achieve the expansion.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Setting any layout will expand it to fill the parent.

          (Z(:^

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

            Ok, thank you!

            Explicit Layouts are actually never needed.

            Here's how to achieve automatic resizing and custom layouts:

            In Qt Designer:
            in Object View:
            right-click the very top QMainWindow
            select Layout and choose arrange horizontally or vertically

            Now the QWidget below the very top QMainWindow receives an implicit layout.

            in Properties of above mentioned QWidget:
                choose sizePolicy Expanding for both directions to have that QWidget resized automatically when the QMainWindow resizes.
            

            To have widgets inside that QWidget resize automatically set their Properties sizePolicy to Expanding.

            To have a different layout for some objects inside that QWidget from horizontal / vertical, put them inside another QWidget, right-click that QWidget in Object View and select Layout and choose arrange vertically or horizontally. That another QWidget now receives an implicit layout which can be handled like the first QWidget's implicit layout here.

            To have a widget with a fixed width / height from the right / bottom border, set its horizontal / vertical sizePolicy to Fixed, set the minimum width / height and have a widget before that widget with sizePolicy Expanding.

            1 Reply Last reply
            1

            • Login

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