qt-interest@trolltech.com
[Top] [All Lists]

Re: Mac OS X Hide QWidget on close rather than exit

Subject: Re: Mac OS X Hide QWidget on close rather than exit
From: "Matteo Bertozzi"
Date: Wed, 23 Jul 2008 06:21:26 +0200
#ifdef Q_WS_MAC
static OSStatus appleEventProcessor(const AppleEvent *ae, AppleEvent *event, long handlerRefCon)
{
    MyApplication *app = (QfApplication *) handlerRefCon;

    OSType aeID = typeWildCard;
    OSType aeClass = typeWildCard;
    AEGetAttributePtr(ae, keyEventClassAttr, typeType, 0, &aeClass, sizeof(aeClass), 0);
    AEGetAttributePtr(ae, keyEventIDAttr, typeType, 0, &aeID, sizeof(aeID), 0);

    if (aeClass == kCoreEventClass) {
        if (aeID == kAEReopenApplication) {
            app->mainWindow()->show();
        }
        return noErr;
    }
    return eventNotHandledErr;
}
#endif

#ifdef Q_WS_MAC
bool MyApplication::macEventFilter (EventHandlerCallRef caller, EventRef event) {
    emit macEvent(caller, event);

    UInt32 eKind = GetEventKind(event);
    UInt32 eClass = GetEventClass(event);
    if (eClass == kEventClassApplication && eKind == kEventAppActivated) {
        mainWindow()->show();
    }

    return(QApplication::macEventFilter(caller, event));
}
#endif

in MyApplication constructor...
#ifdef Q_WS_MAC
    // Install Reopen Application Event (Dock Clicked)
    d->appleEventProcessorUPP = AEEventHandlerUPP(appleEventProcessor);
    AEInstallEventHandler(kCoreEventClass, kAEReopenApplication, d->appleEventProcessorUPP, (long) this, true);
#endif


On Wed, Jul 23, 2008 at 4:20 AM, Keith Esau <keith.esau@xxxxxxx> wrote:
Clicking on the application's dock icon (on Mac) shows the application, not
widgets in the application.

It sounds like the problem is that the closeEvent should be telling the
system to hide the application (to do what Andy is intending). It should not
be calling hide() on the main widget.

Keith
**Please do not reply to me, reply to the list.**

On 07-22-2008 9:29 AM, "Brad Howes" wrote:

> On Jul 22, 2008, at 8:50 AM, Andy Bell wrote:
>
>> I am trying to get a Qt 4.4.0 application to simply hide when the
>> close button is hit in the main widget(and the only one) of the
>> application.  I have reimplemented closeEvent of QWidget and ignored
>> the event to close and the called the slot hide().  This works fine,
>> but when I come to click the application icon in the dock bar it
>> doesn't activate the widget again.
>>
>> Any ideas?
>
>
> How would the application know that clicking on its dock icon should
> reveal a hidden window? You might be able to monitor
> QApplication::macEventFilter() for "dock" events, but I'm not sure
> this would work nor do I know what you would look for.
>
> Brad


--
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/




--
Matteo Bertozzi

<Prev in Thread] Current Thread [Next in Thread>