Results 1 to 5 of 5

Thread: How to "hide window when close button pressed"

  1. #1
    Join Date
    May 2006
    Posts
    32
    Thanks
    15
    Thanked 2 Times in 2 Posts

    Default How to "hide window when close button pressed"

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to "hide window when close button pressed"

    "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).

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

    iGoo (26th July 2006)

  4. #3
    Join Date
    May 2006
    Posts
    32
    Thanks
    15
    Thanked 2 Times in 2 Posts

    Question Re: How to "hide window when close button pressed"

    Quote Originally Posted by wysota
    "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!

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to "hide window when close button pressed"

    Quote Originally Posted by iGoo
    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).

  6. #5
    Join Date
    May 2006
    Posts
    32
    Thanks
    15
    Thanked 2 Times in 2 Posts

    Default Re: How to "hide window when close button pressed"

    "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.

Similar Threads

  1. Replies: 3
    Last Post: 23rd July 2006, 18:02
  2. use button from another Window
    By raphaelf in forum Qt Programming
    Replies: 11
    Last Post: 2nd March 2006, 20:31

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.