Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-40116

nativeEvent function doesn't get called on Mac

    XMLWordPrintable

Details

    • macOS

    Description

      on Mac when an user presses "Ctrl + left click", applications usually interpret it as "right click", because old Mac mouse has only one button.

      Qt therefore automatically translates "Ctrl+Left Click" to "right click". But we don't want this feature for our application, we want it to be "Ctrl+left click".

      In the Qt4 era, we used to do a trick in the macEvent function, such that whenever we see "Ctrl+Left click", we mark a flag and handle this event differently.

      #ifdef _APPLE_
      bool SomeWidget::macEvent(EventHandlerCallRef, EventRef event)
      {
      if ( event is ctrl+left )

      { m_isRightClick = true; return false; }

      return false;
      }

      bool GLCanvas::macEventFilter (EventHandlerCallRef caller, EventRef event)

      { return false; }

      #endif

      We recently moved to Qt5. Since macEvent doesn't exist anymore, we changed our code to the following:

      bool SomeWidget::nativeEvent(const QByteArray & eventType, void * message, long * result)
      {
      if (eventType == "mac_generic_NSEvent")
      {
      EventRef ev = static_cast<EventRef>(message);

      if ( .. event is ctrl+left click...)

      { m_isRightClick = true; }

      }
      else

      { ... }

      return false;
      }

      but this doesn't work anymore, because on Mac nativeEvent never gets called.

      the attachment is a simple program that can reproduce this issue.

      it is modified from the helloGL example. I simply added a nativeEvent function to the QGLWidget.

      the same program can call into nativeEvent on Windows, but won't under Mac.

      Is this a bug or just a missing implementation?

      the Document on this page is very unclear.

      http://qt-project.org/doc/qt-5/qwidget.html#nativeEvent

      it doesn't give any example of using nativeEvent under mac, although it says nativeEvent replaces macEvent.

      Inside the event type table, it only lists:
      Windows "windows_generic_MSG" MSG * LRESULT

      it doesn't mention Mac event type (mac_generic_NSEvent) at all?

      it also doesn't say how to check the event type. is it a string or enum?

      Attachments

        For Gerrit Dashboard: QTBUG-40116
        # Subject Branch Project Status CR V

        Activity

          People

            vestbo Tor Arne Vestbø
            billconan shi yan
            Votes:
            2 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes