Results 1 to 5 of 5

Thread: How to resize parent widget when child widget is resized

  1. #1

    Default How to resize parent widget when child widget is resized

    Does anyone know how I can trigger the parent to resize when its child widget is resized?

    What I have tried is that emit signal in the resizeevent of the child widget and do the slot of the parent widget to resize the parent.
    But unfortunately resizing the parent will cause the child widget to be resized again. So in this way, I get a loop and it doesn't give
    me the result that I expect.

    Can somebody help with that?

  2. #2
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to resize parent widget when child widget is resized

    Hi,

    If you are using layouts it might happen that resizing the parent will re-size its children.

    I am trying to imagine what are you trying to do? How are you resizing the child, with the mouse or by code? What king of widget it is?

    Instead of just resizing the parent, you might need to write some code to separate the re-sizes that happens because of the change in size of the parent from the ones made in the child by your code or mouse. In short, to emit your signal only for just some cases.

    Carlos.

  3. #3
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to resize parent widget when child widget is resized

    I suspect that you should read about sizeHint for classic widgets or QGraphicsWidgets.

    I did something nasty with that (resizing text label on line wrapping) so if you explain you initial problem (not how you are trying to solve it) then I may be able to help.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to resize parent widget when child widget is resized

    It really depends what you are trying to achieve. There is an example of automatically resizing a dialog when an optional child panel is requested. It uses size policy to achieve this.

    If you are programatically changing the size of a child widget to hold some new data/image/whatever then you may be able to force the parent to grow using the minimum size attribute of the child.

    Generally, I consider arbitrarily resizing main windows bad form.

  5. #5

    Default Re: How to resize parent widget when child widget is resized

    Thank you for the replies so far.

    My initial problem is that I add a QTableWidget in a window, the content of the table widget is filled in later. When it is filled in, I call resizeColumnsToContents() to resize the table widget, and that works
    perfectly. But then my window doesn't resize itself so I get window with only part of the table widget visualized. I want to have the window also to be resized so I can have a complete view.

Similar Threads

  1. Replies: 0
    Last Post: 11th November 2011, 11:11
  2. Replies: 1
    Last Post: 11th March 2011, 20:34
  3. child widget resize to parent widget
    By bobFromAccounting in forum Newbie
    Replies: 10
    Last Post: 11th February 2011, 03:53
  4. Replies: 7
    Last Post: 14th January 2010, 09:47
  5. Replies: 4
    Last Post: 3rd October 2009, 09:19

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.