Cocoa WebView on os X does not trigger mouseover events without pressing and holding the mouse button

I am new to Mac development and trying to enable Cocoa WebView using QMacCocoaViewContainer. I have a view loading my html file with several css and javascript files, but the problem I am facing is that mouseover events do not fire when the user moves the mouse over the view.

I determined that if the user presses and holds the left mouse button and moves the mouse, then events are fired. I suppose this is a focal issue, but was not successful in solving this problem. Any help would be great

0
source share
1 answer

I found a similar question in SO: Event related to embedding cocoa webview in a QT application that contains the answer. I can confirm that the solution in this answer works, but only hint. Here is what I did:

  • Repeat the implementation of QApplication :: macEventFilter () in your application.
  • Disable other people's widgets for your application or only for QMacNativeCocoaWidget by doing

    setAttribute(Qt::WA_PaintOnScreen) 
  • In macEventFilter (), check if the event is a MouseMove event:

     NSEvent *e = reinterpret_cast<NSEvent *>(event); if ([e type] == NSMouseMoved) 
  • If so, check to see if the coordinates are within the boundaries of the WebView, and then send a MouseMoved notification to the Notification Center:

     [[NSNotificationCenter defaultCenter] postNotificationName:@"NSMouseMovedNotification" object:nil userInfo:[NSDictionary dictionaryWithObject:e forKey:@"NSEvent"]]; 

When you check to see if the position of the event is in your WebView, remember that the coordinates of cocoa have the origin at the bottom, and in Qt (0, 0) the top left!

+1
source

Source: https://habr.com/ru/post/1485734/


All Articles