PDA

View Full Version : Hide Dialog When Mouse Moves Outisde



stefanadelbert
9th July 2010, 04:48
I have a QDialog with setWindowFlags(Qt::Popup). I want to hide the QDialog as soon as the mouse moves outside the boundaries of the QDialog.

I thought I might be able to use QWidget::focusOutEvent, but moving the mouse off the QDialog doesn't cause the QDialog to lose focus, so that doesn't work.

I thought about tracking the mouse movement using QWidget::mouseMoveEvent, but this will only be called while the mouse is moving over the QDialog and not once it is moving outside the QDialog.

Has anyone done this before or does anyone have any ideas?

aamer4yu
9th July 2010, 05:31
May be you will need QWidget::grabMouse Do read the warnings that come in the doc.

stefanadelbert
9th July 2010, 07:53
I found void QWidget::leaveEvent ( QEvent * event ), which I can use to achieve exactly what I need.