Results 1 to 4 of 4

Thread: recenter child widgets after hide/show

  1. #1
    Join Date
    May 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default recenter child widgets after hide/show

    Hi,

    the QDialogs in my application are often just hidden when some of the buttons is pressed or some other exit-slot is called so that I just can show and don't have to recreate them if they are requested by the user for the 2nd time. Unfortunately this creates some weirdly looking behavior if you accept/kill one of these dialogs at position X, then move the parent window to some other position and show the dialog again. It will then be shown on its last position which is X and not centered on the parent as you'd expect and as it's done if you spawn and therefore create it for the first time.
    Is there a simple way to achieve this without having to recreate the dialog everytime that it's shown and hopefully without writing a hacky routine that makes a recentering on each showEvent?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: recenter child widgets after hide/show

    Sub windows, such as dialogs, are positioned by the windowing system unless they specifically request a position.

    Most windowing systems do not reposition such a window when it has just been hidden and then reshown, basically just setting a position on first show.
    If you want to reposition on each show, you'll have to implement this yourself

    Cheers,
    _

  3. #3
    Join Date
    May 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: recenter child widgets after hide/show

    Yes, I know. I'm just asking what the best practice in a case like this is. The problem is that our widgets are often bloated with functionality which is really bad design but now tough to fix because it has been developed in this way for years and might break a lot of other code if changed. Otherwise I think I'd just kill and recreate the widget the next time it's shown because it's creation should be pretty light-weight then.
    Can I just override the showEvent in my subclasses to repositioning the widgets by myself?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: recenter child widgets after hide/show

    Quote Originally Posted by so Qt View Post
    Can I just override the showEvent in my subclasses to repositioning the widgets by myself?
    Yes.

    Alternatively, if you have many of these sub windows and no common base class, you could also create an event filter based "decorator" that you attach to each window.

    Cheers,
    _

Similar Threads

  1. Replies: 2
    Last Post: 25th February 2015, 19:18
  2. Replies: 4
    Last Post: 18th October 2013, 18:15
  3. Replies: 0
    Last Post: 30th April 2012, 16:17
  4. Replies: 5
    Last Post: 19th April 2010, 00:31
  5. is it possible to animate sliding widgets on show/hide
    By discostu in forum Qt Programming
    Replies: 2
    Last Post: 4th March 2007, 09:59

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.