PDA

View Full Version : How to make child window as a center to parent window



dpn
16th September 2013, 09:05
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.

high_flyer
16th September 2013, 09:36
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?

dpn
16th September 2013, 10:45
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.

high_flyer
16th September 2013, 10:49
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.

dpn
16th September 2013, 12:08
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.

dpn
17th September 2013, 06:45
I found the corresponding flags for Qt::Dialog. I am able to make child window as center and without frame.

Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowTitleHint

Thanks.