0

I am using a QMenu in my application and when I click outside the QMenu to close it, Qt emits a couple of events. I found that on Linux, it emits the following events:

QEvent::MouseButtonPress
QEvent::Close
QEvent::Hide
QEvent::HideToParent
QEvent::UpdateRequest
QEvent::Leave

on Mac OS, the events emitted are as follows:

QEvent::Close
QEvent::Hide
QEvent::HideToParent
QEvent::UpdateRequest
QEvent::Leave

As it is visible that when QMenu is closed, the QEvent::MouseButtonPress is not emitted on Mac environment. I want to know if it is a bug in Qt or it is an intentional behavior.

In my code, I am calculating the coordinates of mouse click when QMenu is closed, in mousePressEvent() method, which I have overriden in my custom menu class which inherits QMenu. But it is breaking the whole application on Mac OS due to the reason highlighted above.

I am using Qt version 5.12.3

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
shubhamcr7
  • 37
  • 1
  • 5

1 Answers1

0

It is likely caused by the fact that on macOs, menus are handled by the operating system.

This is hinted by the QMenu::toNSMenu() function. Unlikely for you NSMenudoes not seems to provide a way to get a mouse click coordinate.

If I may suggest you should change your implementation and not rely on a MousePressEvent on any platform. QMenus can be interacted with using a keyboard, in such case you will not have a MousePressEvent and you will have the same issue.

Benjamin T
  • 8,120
  • 20
  • 37