On 20-Mar-2012, at 10:53 AM, Nikos Chantziaras wrote:

> Maybe this is relevant:
> 
> http://qt-project.org/doc/qt-4.8/qapplication.html#macEventFilter


OK- that was a good lead. It seems that at that point the Cmd-period key event 
*IS* available. Here is my code:

In my subclass of QApplication:

#ifdef MACIGOR
bool IgorAppObject::macEventFilter(EventHandlerCallRef caller, EventRef event)
{
        if (WMNSEventIsCmdPeriod(reinterpret_cast<void *>(event)))
                emit cancelEvent();
        
        return false;
}
#endif

In a .mm (objective C++) file:

bool
WMNSEventIsCmdPeriod(void *event)
{
        NSEvent * nsevent = reinterpret_cast<NSEvent *>(event);
        if ([nsevent type] == NSKeyUp) // presumably, if we see the key up it 
was preceded by a key down. Action should take place on key up.
        {
                std::cout << "NSEvent keydown event" << std::endl;
                if ([nsevent modifierFlags] & NSCommandKeyMask)
                {
                        NSString * chars = [nsevent 
charactersIgnoringModifiers];
                        return [chars characterAtIndex:0] == 0x2E; // Unicode 
encoding for period
                }
        }
        return false;
}

The header containing the prototype for this function declares it to be extern 
"C". It is my understanding that that is required because Objective C++ mangles 
names differently than regular C++.

In addition to the above, I have regular QApplication::notify event filter 
looking for QKeyEvents that match Qt::Key_Cancel. That will provide the same 
functionality on platforms where Qt allows this access (empirically, Windows 
works this way).

Seems like since QApplication::macEventFilter() can see the relevant key 
events, it would be possible for Qt on Cocoa/Macintosh could just Do the Right 
Thing. But maybe not...

-John Weeks

_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to