Results 1 to 12 of 12

Thread: how to close the application when the mouse click outside the window

  1. #1
    Join Date
    Apr 2008
    Posts
    41
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default how to close the application when the mouse click outside the window

    how to close the application when the mouse click outside the window.
    in my application ,I popu a window ,and I want to close it when I click the outside this popu window or the mouse click the desktop.

  2. #2
    Join Date
    Feb 2008
    Posts
    51
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to close the application when the mouse click outside the window

    Hi,
    You can do it in focusOut event.
    Just call close method of your widget.

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to close the application when the mouse click outside the window

    A Qt::Popup window does that automatically.
    J-P Nurmi

  4. #4
    Join Date
    Apr 2008
    Posts
    41
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to close the application when the mouse click outside the window

    Quote Originally Posted by Sandip View Post
    Hi,
    You can do it in focusOut event.
    Just call close method of your widget.
    This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) for the widget.
    But I want the mouse click outside the window the window can be closed.

  5. #5
    Join Date
    Apr 2008
    Posts
    41
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to close the application when the mouse click outside the window

    Quote Originally Posted by jpn View Post
    A Qt::Popup window does that automatically.
    The window is no the popu window,it is a normal window.

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to close the application when the mouse click outside the window

    Then try catching QEvent::WindowDeactivate.
    J-P Nurmi

  7. #7
    Join Date
    Apr 2008
    Posts
    41
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to close the application when the mouse click outside the window

    Quote Originally Posted by jpn View Post
    Then try catching QEvent::WindowDeactivate.
    I tryed ,but it doesn't work.

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to close the application when the mouse click outside the window

    Quote Originally Posted by duduqq View Post
    I tryed ,but it doesn't work.
    Sure it works if you just do it correctly... It would be easier to state the problem if you told or even showed us what you actually tried.
    J-P Nurmi

  9. #9
    Join Date
    Apr 2008
    Posts
    41
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to close the application when the mouse click outside the window

    Quote Originally Posted by jpn View Post
    Sure it works if you just do it correctly... It would be easier to state the problem if you told or even showed us what you actually tried.
    My app is a QMainWindow ,when I push the toolbutton is popu the window,
    I want to close the popu window when the mouse press every where ,event press out side the widget.
    My app screenshot is like this
    Attached Images Attached Images

  10. #10
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to close the application when the mouse click outside the window

    When the mouse is clicked anywhere inside the application window, the popup (if its a menu) should close automatically. When the mouse is clicked anywhere outside your application window, QMainWindow's WindowDeactivate event is invoked. You will need to reimplement QMainWindow's event function in your class, catch the WindowDeactivate even and check if your popup is open or not. Close (or maybe hide ) it accordingly.

  11. #11
    Join Date
    Apr 2008
    Posts
    41
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to close the application when the mouse click outside the window

    it is very eary,just use
    setWindowFlags(Qt::Popup) ;
    and close it at the mousePressEvent()

  12. #12
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to close the application when the mouse click outside the window

    Quote Originally Posted by jpn View Post
    A Qt::Popup window does that automatically.
    I guess you didnt pay attention to Jpns post :P

Similar Threads

  1. close window when click on a label
    By sabeesh in forum Qt Programming
    Replies: 3
    Last Post: 29th October 2007, 07:35
  2. Independant window in an application
    By titoo in forum Qt Programming
    Replies: 4
    Last Post: 28th February 2007, 11:07
  3. Replies: 1
    Last Post: 9th February 2007, 09:41
  4. Replies: 2
    Last Post: 24th July 2006, 18:36
  5. Replies: 3
    Last Post: 23rd July 2006, 18:02

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.