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. How do I get the "natural" widget size?
QtWS25 Last Chance

How do I get the "natural" widget size?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 21.4k 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
    reactive
    wrote on last edited by
    #1

    I'm trying to display a QLabel with its "natural" height but a custom width.
    I've tried to get its height with w.height(), w.sizeHint().height() and w.normalGeometry().height().
    The 1st is almost the height of the whole screen, the 2nd is just barely the height of the
    text and doesn't seem to respect setContentMargins() and the 3rd returns 0.

    Thanks!

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Hi reactive,

      • w.height() should return the current height of the widget.
      • w."sizeHint":http://doc.qt.nokia.com/latest/qwidget.html#sizeHint-prop () returns the size, the widget likes to have. This should be the content + perhaps border etc. It can be bigger than the content.
      • w."minimumSizeHint":http://doc.qt.nokia.com/latest/qwidget.html#minimumSizeHint-prop () returns the minimum size, the widget wants to have to be able to display the content. It's always minimumSizeHint() <= sizeHint().
      • "normalGeometry":http://doc.qt.nokia.com/latest/qwidget.html#normalGeometry-prop () makes no sense for non top level widgets

      The margin should be taken into account for a QLabel for sizeHint and minimumSizeHint.

      Afaik, setContentMargins is a function of the layout, not of the widget. This space is added between the widgets in the layout. See this "link":http://doc.qt.nokia.com/latest/qlayout.html#setContentsMargins .

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

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

        Afaik, setContentMargins is a function of the layout, not of the widget.

        As usual, thanks Gerolf. I should have been using setMargin().
        sizeHint() is the one I was looking for.

        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