Results 1 to 6 of 6

Thread: How to make child window as a center to parent window

  1. #1
    Join Date
    Nov 2012
    Posts
    21
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default How to make child window as a center to parent window

    Hi,

    WindowA is derived from QMainWindow.

    DlgA is derived from QDialog. Removed frame for dilaog box by using setWindowFlags(Qt::FramelessWindowHint);.

    On button click event, WindowA displays DlgA.

    Now, I want to make DlgA as center window for WindowA. I cannot send QMainWindow object as a parent to DlgA constructor. It accepts Dialog object only as a parent.

    What is better way to handle this?

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to make child window as a center to parent window

    Now, I want to make DlgA as center window for WindowA.
    This is the default behavior for a QDialog.
    I cannot send QMainWindow object as a parent to DlgA constructor.
    why not?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    dpn (17th September 2013)

  4. #3
    Join Date
    Nov 2012
    Posts
    21
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to make child window as a center to parent window

    DlgA moving to outside of parent window.

    Note: Didn't send parent object to dialog box. why because dialog is not accepting main window pointer in constructor.

  5. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to make child window as a center to parent window

    DlgA moving to outside of parent window.
    Can you be any more cryptic?
    Do you want help or not?

    why because dialog is not accepting main window pointer in constructor.
    ??
    This is C++.
    QMainWindow is a QWidget, and thus you must be doing something wrong since QDialog takes a QWidget as a parent.
    Show your code.
    Last edited by high_flyer; 16th September 2013 at 13:03.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. The following user says thank you to high_flyer for this useful post:

    dpn (17th September 2013)

  7. #5
    Join Date
    Nov 2012
    Posts
    21
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to make child window as a center to parent window

    Thanks. I am able to set parent and make it center.

    When I set window flag(setWindowFlags(Qt::FramelessWindowHint) in Dialog constructor, then it's not visible on my main window.

    Without enabling flags, it's working perfectly.

    How can I make child window as a center of parent window without frame.
    Last edited by dpn; 16th September 2013 at 12:41.

  8. #6
    Join Date
    Nov 2012
    Posts
    21
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to make child window as a center to parent window

    I found the corresponding flags for Qt:ialog. I am able to make child window as center and without frame.

    Qt:ialog | Qt::FramelessWindowHint | Qt::WindowTitleHint

    Thanks.

Similar Threads

  1. resizing child window with parent window
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 3
    Last Post: 8th May 2012, 19:02
  2. Parent window over child
    By neolol in forum Qt Programming
    Replies: 4
    Last Post: 15th May 2009, 21:15
  3. Parent Child for window
    By febil in forum Qt Programming
    Replies: 6
    Last Post: 1st April 2009, 05:00
  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.