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

QMacCocoaViewContainer mouse tracking doesn't work amongst other things in Qt 4.8 RC1

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Not Evaluated Not Evaluated
    • 5.3.2
    • 4.8.0
    • None
    • Mac OS X 10.5.8 & 10.7.2

      Various issues with QMacCocoaViewContainer make it almost useless in Qt 4.8 RC1. First of all the widget needs to be set to native mode. Second of all the initial size of the QWidget/NSView seems to be reset to zero when the Cocoa view is set. Third, mouse tracking doesn't work at all.

      Here's a workaround implementation for hacking around these show stoppers:

      // mycocoaviewcontainer.h:
      
      #include <QMacCocoaViewContainer>
      
      class MyCocoaViewContainer : public QMacCocoaViewContainer
      {
      public:
          MyCocoaViewContainer(void *cocoaViewToWrap, QWidget *parent = 0);
      
      protected:
          virtual void mouseMoveEvent(QMouseEvent *event);
      
      private:
          bool ignoreNextMouseMove;
      };
      
      
      // mycocoaviewcontainer.mm:
      
      #include "mycocoaviewcontainer.h"
      
      MyCocoaViewContainer::MyCocoaViewContainer(void *cocoaViewToWrap, QWidget *parent) : QMacCocoaViewContainer(0, parent),
          ignoreNextMouseMove(false)
      {
          setAttribute(Qt::WA_NativeWindow);
      
          NSView *view = (NSView*)cocoaViewToWrap;
          setFixedSize(view.bounds.size.width, view.bounds.size.height);
      
          setCocoaView(cocoaViewToWrap);
      
          setMouseTracking(true);
      }
      
      void MyCocoaViewContainer::mouseMoveEvent(QMouseEvent *event)
      {
          if (event->buttons() || ignoreNextMouseMove)
              return;
      
          NSUInteger modifierFlags = 0;
          if (event->modifiers() & Qt::ShiftModifier)
              modifierFlags |= NSShiftKeyMask;
          if (event->modifiers() & Qt::ControlModifier)
              modifierFlags |= NSCommandKeyMask;
          if (event->modifiers() & Qt::AltModifier)
              modifierFlags |= NSAlternateKeyMask;
          if (event->modifiers() & Qt::MetaModifier)
              modifierFlags |= NSControlKeyMask;
          if (event->modifiers() & Qt::KeypadModifier)
              modifierFlags |= NSNumericPadKeyMask;
      
          NSView *view = (NSView*)cocoaView();
      
          ignoreNextMouseMove = true;
      
          [view mouseMoved:[NSEvent mouseEventWithType:NSMouseMoved location:[view convertPoint:NSMakePoint(event->x(), event->y()) toView:nil] modifierFlags:modifierFlags timestamp:0 windowNumber:(([view window] != nil) ? [[view window] windowNumber] : 0) context:[NSGraphicsContext currentContext] eventNumber:0 clickCount:0 pressure:0]];
      	
          ignoreNextMouseMove = false;
      }
      

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

            Unassigned Unassigned
            antipro Karel Bassez
            Votes:
            4 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes