Results 1 to 8 of 8

Thread: Force geometry update of hidden widget

  1. #1
    Join Date
    May 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Force geometry update of hidden widget

    Is there any way to force the update of geometry for a hidden (i.e. isVisible() == false) widget? It seems like all of the geometry updating routines wait until the widget is shown to actually update the layout/geometry.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Force geometry update of hidden widget

    There is a way but it is a hack and you shouldn't do it, especially that it's completely meaningless. Why do you need it?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Force geometry update of hidden widget

    I have a QMenu with an embedded widget (provided by a QWidgetAction). The content of the embedded widget is updated between showings of the menu which could cause the size of the embedded widget to change.

    It appears to me that when the menu tries to calculate its new size for the next show the widget's layout has not been updated to reflect the new required size because the updates are applied while the widget was not visible. The widget's sizeHint is not updated until it is actually shown, too late to influence the size of the menu. Consequently, the menu uses the stale size of the widget, and the size of the menu is always lagging behind the size of the widget by one update cycle.

    I was thinking if I could force the widget to update its layout (really its sizeHint) prior to being shown, the QMenu could obtain the correct sizeHint from the widget.
    Last edited by stburton; 8th December 2009 at 22:48.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Force geometry update of hidden widget

    Try calling ensurePolished() on the menu and/or the widget before you try to display the menu. Maybe this will be enough.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    May 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Force geometry update of hidden widget

    Alas, that does not seem to do the trick.

    I have hit upon a work-around that I can make use of for the time being.

    If the top-level layout of the widget is altered then the widget will report the correct sizeHint to the menu prior to being shown. However, if the contents of only child widget layouts are altered, changes do not percolate up until the widget is actually being shown (too late).

    Forcing either only a single top-level layout or a change to the top-level layout prior to being shown seems to do the trick so that the correct sizeHint is reported to the QMenu.

    <sigh>

    This is really still pretty dirty and I would still be interested if anyone has a better way.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Force geometry update of hidden widget

    You can call invalidate() on the layout. It should recalculate itself then. If not then there is this secret attribute that convinces the widget it is being shown and then you should be able to force its layout to recalculate. But try other things first, this is not something very reliable.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    May 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Force geometry update of hidden widget

    Yeah, I had tried 'invalidate' as like the first thing. No dice.
    I was kind of surprised it had no effect where as actually causing a change to the layout does have an effect.

    secret attribute that convinces the widget it is being shown
    Which attribute is that?
    Last edited by stburton; 9th December 2009 at 00:50.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Force geometry update of hidden widget

    Qt::WA_WState_ExplicitShowHide set to true and Qt::WA_WState_Hidden set to false. Be sure to revert the values (especially the second one) before you actually show the widget on screen.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  2. Replies: 2
    Last Post: 21st October 2009, 08:13
  3. update widget from separate thread
    By method in forum Qt Programming
    Replies: 5
    Last Post: 10th July 2009, 14:33
  4. Resize widget force layout resizing
    By ^NyAw^ in forum Qt Programming
    Replies: 17
    Last Post: 11th February 2009, 11:27
  5. closing dialog in hidden main Widget
    By Lele in forum Qt Programming
    Replies: 3
    Last Post: 6th December 2006, 10:35

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.