PDA

View Full Version : How to "hide window when close button pressed"



iGoo
26th July 2006, 10:03
Hi,guys:

I have a mainwindow with some child windows in QWorkspace.
I want that any child will be hidden instead of being closed when the 'X' button pressed.


Any suggestion please?



Thanks in Advance.;)

wysota
26th July 2006, 10:06
"closed" and "hidden" are synonyms, so in reality they are hidden when you close them, unless you pass a destructive close flag to them. But if you insist on making sure of that, override their closeEvent and call hide() there (remember to ignore the event afterwards). Just make sure you don't disable closing the window completely (meaning that at some point the closeEvent will have to be accepted).

iGoo
26th July 2006, 10:28
"closed" and "hidden" are synonyms, so in reality they are hidden when you close them, unless you pass a destructive close flag to them. But if you insist on making sure of that, override their closeEvent and call hide() there (remember to ignore the event afterwards). Just make sure you don't disable closing the window completely (meaning that at some point the closeEvent will have to be accepted).

two points please:
1 、how to "ignore the event afterwards"
2 、"Just make sure you don't disable closing the window completely"
when the mainwindow closed,together with QWorkspace destroyed,can the child be
clean completely?


Thanks!

wysota
26th July 2006, 10:40
1 、how to "ignore the event afterwards"
QEvent::ignore()

2 、"Just make sure you don't disable closing the window completely"
when the mainwindow closed,together with QWorkspace destroyed,can the child be
clean completely?
If you ignore the close event, the close event of the parent will be ignored too automatically (AFAIR), so you might run into a problem of not being able to close your application without killing it. IMO you shouldn't reimplement the close event just to be able to call hide(), as close() does exactly the same thing (the only difference is with the destructive close flag set).

iGoo
26th July 2006, 10:53
"the only difference is with the destructive close flag set"

I just notice the statement above,thanks.

I want all of my child windows to receive some messages while work thread processing,but I don't want the user to see all of them except the user want.

So I want to "hide" but not "close" the window in which situation,the message sent
to them may be lost.

I will try now.
Thanks again.:o