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. Resize top level window to fit contents?
Qt 6.11 is out! See what's new in the release blog

Resize top level window to fit contents?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 17.4k 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.
  • C Offline
    C Offline
    Claghorn
    wrote on last edited by
    #1

    I'm using a custom dialog as a top level window which, among other things, shows some images in QLabels. If I change the QLabel size I can grow the dialog perfectly fine and everything is still laid out nicely. If I shrink the QLable image size, I'm left with vast amounts of empty space in my dialog. I can grab the window manager handle and resize the window back down to where things will just fit, but I can't for the life of me figure out how the devil to make Qt do that for me. The adjustSize() function is described like it is exactly what I want, but calling it has no effect. How do I make this happen short of sending phony mouse events to emulate a window resize operation?

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

      You could try out:

      @
      resize(sizeHint());
      @

      The point is, the layouts keep track that all widgets fit in the area. But if there is too much space, it's not shrunk.

      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
      • C Offline
        C Offline
        Claghorn
        wrote on last edited by
        #3

        Nah, resize(sizeHint()) has the same zero-effect as everything else I've tried. I may have to destroy the main window and create a new copy from scratch (you'd think there would be a way to ask the top layout to essentially do just that, but if there is, I can't find it).

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Claghorn
          wrote on last edited by
          #4

          I finally got it to work, what I needed to do was this:

          QTimer::singleShot(0, this, SLOT(resizeMe()));

          where the resizeMe() slot calls:

          resize(minimumSizeHint());

          The minimum size isn't recomputed till the event loop gets some stuff to run, so by running from the zero length timeout, I can do the resize after the hint is properly updated.

          1 Reply Last reply
          2

          • Login

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