How to detect mouse click outside of widget?
-
wrote on 5 Dec 2018, 20:14 last edited by
I've created a modal QDialog which shows a single QLineEdit. I'm using it to allow the user to change the name of a data object. I'd like to automatcially close my dialog with a call to reject() if the user ever clicks outside of the dialog area. I've added a mousePressEvent() to my dialog's class, but it never gets called.
Is there a way for me to tell if the user clicks away from my dialog box?
-
I've created a modal QDialog which shows a single QLineEdit. I'm using it to allow the user to change the name of a data object. I'd like to automatcially close my dialog with a call to reject() if the user ever clicks outside of the dialog area. I've added a mousePressEvent() to my dialog's class, but it never gets called.
Is there a way for me to tell if the user clicks away from my dialog box?
@kitfox said in How to detect mouse click outside of widget?:
Is there a way for me to tell if the user clicks away from my dialog box?
either listen to a
QEvent::WindowDeactivate
event or useqApp->installEventFilter(filter)
and listen for mouse press events -
wrote on 6 Dec 2018, 08:01 last edited by
Alternatively, you can use grabMouse() to receive mouse events. However, that will cause the first click outside your dialog (the one where you close the dialog) to be eaten up.
2/3