Unsolved How to detect mouse click outside of widget?
-
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 -
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.