0

I have a QMainWindow application that generates multiple QWidget popups. I would like to know how I can destroy the pop up QWidgets if the user clicks on the main QMainWindow. I am not sure how to proceed with the resolution of this problem. I do not want to interfere with any QMainWindow events, I just want to destroy the additional pop up windows by any mouse click outside of the pop up widgets area. Is it possible or recommended via signal slot mechanism or eventFilter? Is it possible without dealing with (x,y) coordinates?

Thanks for the suggestions.

user3840530
  • 290
  • 1
  • 4
  • 14
  • Should those widgets still provide mouse interactions? A [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) would help, especially to know how those widgets are created and their window flags (if any is set). – musicamante May 13 '20 at 21:06
  • @musicamante No, the windows should be completely destroyed. I will try to disentangle and post an example. The pop up windows are frameless and stay on top windows. – user3840530 May 14 '20 at 12:04

1 Answers1

0

I managed to solve my problem. I implemented a custom label (like this) that contains a mousePressedEvent. On clicking this label a Pop widget is generated. The mousePressEvent is not propagated any further from the label. Then I implemented a mousePressedEvent in the QMainWindow where I check for existence of popup windows. If they exist, I close them all. Note that If I do not stop mouse propagation in the label mousePressEvent, on clicking the label the pop window is generated but it is immediately closed by the QMainWindow mousePressEvent because (most likely) the event is propagating to QMainWindow. At least, that solves my problem.

Thanks

user3840530
  • 290
  • 1
  • 4
  • 14
  • 1
    While your solution might have helped *your* issue, your answer doesn't help StackOverflow that much, since you didn't provide [minimal, reproducible examples](https://stackoverflow.com/help/minimal-reproducible-example) for both your question *and* your answer. I think I can understand what you're describing, but users with less experience who might face a similar issue might not, and providing an MRE really helps the whole community. I'm not downvoting your answer (and I'm afraid that I should), but I suggest to edit it and provide actual code to better explain how you achieved what you did. – musicamante May 17 '20 at 02:32