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. QGridLayout / QVBoxLayout- have a widget disappear when not enough space?
Forum Updated to NodeBB v4.3 + New Features

QGridLayout / QVBoxLayout- have a widget disappear when not enough space?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 285 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.
  • N Offline
    N Offline
    NightShadeI
    wrote on last edited by
    #1

    Hi there,

    im new to QLayouts and just started learning them. As a challenge im trying to emulate some UI.

    Ive got a parent widget which may be resized. It contains 2 child widgets. The top row widget is required to take at least 80 pixels in space. The bottom widget can take as much leftover as it likes, as long as the parent widget is at least 80 pixels in size.

    The top widget can also resize but only when we reach below 80 pixels.

    So:

    Parent widget 30 pixels => Only top widget shows, 30 pixels in height
    Parent widget 80 pixels => Only top widget shows, 80 pixels in height
    Parent widget 120 pixels => Top widget 80 pixels in height, bottom widget 40 pixels in height.

    No matter what I try, the bottom widget always takes at least 1 pixel of space. I want it to vanish completely. Is this possible? or what would the most elegant way to do this be?

    Thanks :) Am using QT 6.5

    Axel SpoerlA 1 Reply Last reply
    0
    • N NightShadeI

      Hi there,

      im new to QLayouts and just started learning them. As a challenge im trying to emulate some UI.

      Ive got a parent widget which may be resized. It contains 2 child widgets. The top row widget is required to take at least 80 pixels in space. The bottom widget can take as much leftover as it likes, as long as the parent widget is at least 80 pixels in size.

      The top widget can also resize but only when we reach below 80 pixels.

      So:

      Parent widget 30 pixels => Only top widget shows, 30 pixels in height
      Parent widget 80 pixels => Only top widget shows, 80 pixels in height
      Parent widget 120 pixels => Top widget 80 pixels in height, bottom widget 40 pixels in height.

      No matter what I try, the bottom widget always takes at least 1 pixel of space. I want it to vanish completely. Is this possible? or what would the most elegant way to do this be?

      Thanks :) Am using QT 6.5

      Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #2

      @NightShadeI
      Could you post the code creating the widgets and layouts?

      Software Engineer
      The Qt Company, Oslo

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

        There isn't really code as such as none of the many things I have tried have worked. I'm more asking for what WILL work.

        I've discovered the issue is my content margins in the 2nd row (there is a nested QGridLayout). If I set the nested QGridLayout in the 2nd row to have content margins of all zero it works.

        I don't want to have to do this , and still want some way to have the top 80 pixels for the top row only , even if it means the 2nd widget goes out of drawing view.

        N 1 Reply Last reply
        0
        • N NightShadeI

          There isn't really code as such as none of the many things I have tried have worked. I'm more asking for what WILL work.

          I've discovered the issue is my content margins in the 2nd row (there is a nested QGridLayout). If I set the nested QGridLayout in the 2nd row to have content margins of all zero it works.

          I don't want to have to do this , and still want some way to have the top 80 pixels for the top row only , even if it means the 2nd widget goes out of drawing view.

          N Offline
          N Offline
          NightShadeI
          wrote on last edited by NightShadeI
          #4

          @NightShadeI

          This is the workaround I was able to end up doing

          class ZeroSpaceGrid : public QGridLayout {
          public:
              explicit ZeroSpaceGrid(QWidget* aParent)
                  : QGridLayout{aParent}
              {}
          
              QSize minimumSize() const final { return QSize{0, 0}; }
          };
          

          I don't like it though. Surely there must be a nicer way to have 2 rows of items, and not have the one with content margins stick around constantly given its min size is non-zero? This feels a hit hacky.

          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