Results 1 to 3 of 3

Thread: Centering child window in parent

  1. #1
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Centering child window in parent

    When opening a child window, I want the default behavior to open the window in the center of the parent window. Research suggests that I would have to calculate the childs position based on the parent geometry, but I'm sure there must be an easier way (and I'm not sure how this would work when the parent is on a different monitor to which the child opens on by default)

  2. #2
    Join Date
    Aug 2011
    Location
    Seoul, Korea
    Posts
    46
    Thanks
    9
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Centering child window in parent

    (as a novice) I wonder whether Qt provides an interface to deal with multiple monitors and their properties (i.e. resolution and geometric relationships). If there is then it must not be that hard I believe.
    Dong Back Kim

  3. #3
    Join Date
    Apr 2009
    Location
    Italy
    Posts
    70
    Thanks
    23
    Thanked 15 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Centering child window in parent

    If the child window is a QDialog, then it will be centered on the parent (exact wording from the docs is "it is centered on top of the parent's top-level widget")

    For other windows, I am using the following code:

    Qt Code:
    1. move(
    2. parentWidget()->window()->frameGeometry().topLeft() +
    3. parentWidget()->window()->rect().center() -
    4. rect().center());
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Parent window over child
    By neolol in forum Qt Programming
    Replies: 4
    Last Post: 15th May 2009, 21:15
  2. Parent Child for window
    By febil in forum Qt Programming
    Replies: 6
    Last Post: 1st April 2009, 05:00
  3. connecting child to parent window...
    By sumit in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2008, 21:28
  4. How to close parent window from child window?
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 14th October 2008, 11:40
  5. Replies: 11
    Last Post: 4th June 2008, 07:22

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.