Results 1 to 3 of 3

Thread: Resize main window after hiding an element

  1. #1
    Join Date
    Oct 2009
    Posts
    19
    Thanks
    2

    Default Resize main window after hiding an element

    I have a textarea on my page and a hide and a show button that controls the textarea. When I click 'hide' the textarea hides but I'm left with a blank space area that was previously filled with my textarea. I'd like to have the main window resize when 'hide' is clicked. I found updateGeometry() But the window is resizeable. Is that only available for static values? thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Resize main window after hiding an element

    I think you are looking for something like that: http://www.qtcentre.org/wiki.php?title=Expanding_dialog.

    The magic word is "setSizeConstraint(QLayout::SetFixedSize)"

  3. #3
    Join Date
    Feb 2012
    Location
    Los Angeles
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Resize main window after hiding an element

    This is one I have just developed an answer for!!! ( Note: this will be given in PyQt4 form )

    I have needed the ability to be able to re-size my app window when showing and hiding extra panels.
    However in the past I ended up just reconfiguring the UI and/or work flow so that re-sizing the window wasn't necessary. However now it is a needed must.

    The window can be re-sized during its creation. The window can be re-sized directly (e.g. self.resize( xSize, ySize )
    However if you create some lines of code that capture the needed sizes, hides the desired section, recalculates what the size should be, the re-size seems to be not take at all.

    (example)
    curHgt = self.size().height()
    curWth = self.size().width()
    myFrmHgt = self.ui.reviewFrm.size().height()
    self.ui.reviewFrm.hide()
    self.resize( curWth, (curHgt - myFrmHgt ) )


    Nothing. Doesn't work. Why not?

    It today's hunt for an answer still did not come up with a viable answer. There are several offerings for options. Hunt up the widget hierarchy, invalidate, adjustSize. A rather exhaustive layout shaking that just will not work if you are attempting to re-size the the main window. There was also an overwhelming response of saying to set your constraint to FixedSize. But that rather defeats the entire purpose, kinda like saying to cut your hand off at the wrist if you have a hang nail.

    However I did stumble across someone that had some success with digging in and discovering that the reason the re-size isn't taking hold is because of the queue of Posted Events that will reset the resize.

    His solution was to run the QApplication.sendPostedEvents() just before doing your application re-size, so that the queued events don't reset your window.
    Yes, and No.
    Yes, this is the solution, and I am sure there is a prettier way of doing it, but you need to really shake the the queue out like a washed paint roller first.

    Here is my simple snippet that I set up that so far seems to be solid.

    result = [ self.size().width(), self.size().height() ]
    if self.ui.reviewFrm.isVisible():

    result[1] -= self.ui.reviewFrm.size().height()
    self.ui.reviewFrm.hide()

    while self.size().height() > result[1]:
    self.appy.sendPostedEvents()
    self.resize( result[0], result[1] )


    (Note: self.appy is where I had stored the application object)
    Nope. It ain't pretty. However at most I have only seen it shake the paint roller twice before the Posted Events allowed for the window to resize.
    No need to lock constraints or shake the parent widgets or climb through the hierarchy looking for size hints.
    Last edited by B4adle7; 23rd February 2012 at 00:28.

Similar Threads

  1. Hiding a window from the taskbar
    By andyp in forum Qt Programming
    Replies: 1
    Last Post: 16th August 2009, 19:34
  2. Fix element in risizing window
    By JoZCaVaLLo in forum Newbie
    Replies: 4
    Last Post: 26th June 2009, 11:35
  3. Replies: 11
    Last Post: 11th August 2008, 10:14
  4. Problem hiding main window on minimize
    By bpetty in forum Newbie
    Replies: 5
    Last Post: 18th September 2007, 18:41
  5. Replies: 15
    Last Post: 23rd March 2007, 17:16

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.