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. Understanding Widget sizing
Forum Updated to NodeBB v4.3 + New Features

Understanding Widget sizing

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 653 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.
  • B Offline
    B Offline
    Bert59
    wrote on 4 Jun 2021, 10:17 last edited by
    #1

    I'm learning Qt and try to understand how widget sizing is working.
    I have made a simple layout including a Gaphics view and a Button as shown below:
    bc32c9c4-3041-42e6-a142-b8d3c240275e-image.png

    Both widgets are placed in a vertical layout and the sizes in the Designer are as follows:
    960a8219-faa5-470b-a476-4645fdabeeec-image.png
    2589925b-f893-48ca-8d5b-33e28a7b7b42-image.png

    So w=576 and h=393 for the Graphics view and w=576 and h=28 for the button.

    For testing I have added the following code to the constructor:
    12516f0f-d40a-49fd-82e2-9acf5055dfb8-image.png

    My first question is why is sizeHint written in italics and size in normal?

    Running the program provides the following outputs:
    Graphics view size: QSize(100, 30)
    Button size: QSize(100, 30)
    Graphics view size hint: QSize(256, 192)
    Button size hint: QSize(93, 28)

    None of these numbers are matching with the numbers in the designer, why? Where are these numbers comming from?

    Then, I have reimplemented the resizeEvent function and copied the qDebug lines in it.
    ffa9cdc4-d186-4737-afc0-ed3324460bae-image.png

    Now the outputs are as follows:
    648d647c-8816-4467-bd3b-c2442aa5251f-image.png

    Now the sizes match with those from the Designer but why the sizehint of the Graphics view has changed and the size hint of the button has not?

    When changing the size of the window with the mouse the minimum size is limited to the following numbers.
    d334e734-a93f-4082-a44c-54b9d3e7e7f3-image.png

    Again, where are these numbers comming from and why is the window limited to this size?

    Is there a place in the documentation where these behaviors are described in depth?

    J 1 Reply Last reply 4 Jun 2021, 10:21
    0
    • B Offline
      B Offline
      Bert59
      wrote on 6 Jun 2021, 13:29 last edited by
      #3

      Hi,
      This link may help:
      https://myprogrammingnotes.com/size-qt-widgets-determined.html

      1 Reply Last reply
      3
      • B Bert59
        4 Jun 2021, 10:17

        I'm learning Qt and try to understand how widget sizing is working.
        I have made a simple layout including a Gaphics view and a Button as shown below:
        bc32c9c4-3041-42e6-a142-b8d3c240275e-image.png

        Both widgets are placed in a vertical layout and the sizes in the Designer are as follows:
        960a8219-faa5-470b-a476-4645fdabeeec-image.png
        2589925b-f893-48ca-8d5b-33e28a7b7b42-image.png

        So w=576 and h=393 for the Graphics view and w=576 and h=28 for the button.

        For testing I have added the following code to the constructor:
        12516f0f-d40a-49fd-82e2-9acf5055dfb8-image.png

        My first question is why is sizeHint written in italics and size in normal?

        Running the program provides the following outputs:
        Graphics view size: QSize(100, 30)
        Button size: QSize(100, 30)
        Graphics view size hint: QSize(256, 192)
        Button size hint: QSize(93, 28)

        None of these numbers are matching with the numbers in the designer, why? Where are these numbers comming from?

        Then, I have reimplemented the resizeEvent function and copied the qDebug lines in it.
        ffa9cdc4-d186-4737-afc0-ed3324460bae-image.png

        Now the outputs are as follows:
        648d647c-8816-4467-bd3b-c2442aa5251f-image.png

        Now the sizes match with those from the Designer but why the sizehint of the Graphics view has changed and the size hint of the button has not?

        When changing the size of the window with the mouse the minimum size is limited to the following numbers.
        d334e734-a93f-4082-a44c-54b9d3e7e7f3-image.png

        Again, where are these numbers comming from and why is the window limited to this size?

        Is there a place in the documentation where these behaviors are described in depth?

        J Online
        J Online
        JonB
        wrote on 4 Jun 2021, 10:21 last edited by JonB 6 Apr 2021, 10:22
        #2

        @Bert59
        To answer just why the numbers are not what you expect in the constructor. In a word, sizes only mean anything after a widget is actually shown. That's why, for example, they are correct in resizeEvent(). Before .show() they seem to be almost anything, don't rely on them.

        1 Reply Last reply
        3
        • B Offline
          B Offline
          Bert59
          wrote on 6 Jun 2021, 13:29 last edited by
          #3

          Hi,
          This link may help:
          https://myprogrammingnotes.com/size-qt-widgets-determined.html

          1 Reply Last reply
          3

          1/3

          4 Jun 2021, 10:17

          • Login

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