Detect if the user clicked outside a specific frame (lost the focus)
-
Hello, I implemented a slide menu by using some animation and QFrame and layouts, and now I want that slide menu to close/hide whenever the user clicks outside it. So how can I achieve that?
I already implemented the hide/close functionality, I only need a way to detect the user interacts with the GUI.
As the QMenu, when you click outside it , it will be hidden
-
Do you have set the correct focus policy (as described in the documentation) and also enabled mouse tracking? With mouse tracking you can override mouseMoveEvent() to see when it's going at the border and then closing your widget.
-
You can use e.g. QWidget::focusOutEvent()
-
You can use e.g. QWidget::focusOutEvent()
@Christian-Ehrlicher , Thank you for your support.
Actually, I tried that and I put a print("test") in that function to see if it has been called, but it hasn't, and not worked with me. -
Do you have set the correct focus policy (as described in the documentation) and also enabled mouse tracking? With mouse tracking you can override mouseMoveEvent() to see when it's going at the border and then closing your widget.
-
Do you have set the correct focus policy (as described in the documentation) and also enabled mouse tracking? With mouse tracking you can override mouseMoveEvent() to see when it's going at the border and then closing your widget.
@Christian-Ehrlicher
Well, i guess i did not, I will read the doc about focus policy and get back here. -
Do you have set the correct focus policy (as described in the documentation) and also enabled mouse tracking? With mouse tracking you can override mouseMoveEvent() to see when it's going at the border and then closing your widget.
This post is deleted! -
Do you have set the correct focus policy (as described in the documentation) and also enabled mouse tracking? With mouse tracking you can override mouseMoveEvent() to see when it's going at the border and then closing your widget.
@Christian-Ehrlicher Thanks it worked correctly :D I have a kinda large project, and somewhere I was setting setFoucs so some kind of widget caused the weird actions.