PDA

View Full Version : how to close the application when the mouse click outside the window



duduqq
10th July 2008, 13:44
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.

Sandip
10th July 2008, 15:23
Hi,
You can do it in focusOut event.
Just call close method of your widget.

jpn
10th July 2008, 17:57
A Qt::Popup window does that automatically.

duduqq
11th July 2008, 01:38
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.

duduqq
11th July 2008, 01:40
A Qt::Popup window does that automatically.
The window is no the popu window,it is a normal window.

jpn
11th July 2008, 08:13
Then try catching QEvent::WindowDeactivate.

duduqq
13th July 2008, 03:21
Then try catching QEvent::WindowDeactivate.
I tryed ,but it doesn't work.

jpn
13th July 2008, 10:52
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.

duduqq
14th July 2008, 04:18
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

munna
14th July 2008, 06:56
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.

duduqq
15th July 2008, 11:18
it is very eary,just use
setWindowFlags(Qt::Popup) ;
and close it at the mousePressEvent()

aamer4yu
15th July 2008, 13:11
A Qt::Popup window does that automatically.
I guess you didnt pay attention to Jpns post :P