Can QEvent setType?



  • I want to send a Deactivate event to application,
    but found that the new event
    QEvent event(QEvent::ApplicationDeactivate)
    can't be sent. (sendEvent() return false).

    then I need to change event type of the application current event.
    but I found QEvent dont have a setType() Function.

    How can I do that?



  • sendEvent() returns the value that was returned from the event handler. QCoreApplication has no (default) implementation for ApplicationActivate and ApplicationDeactivate, thus false is returned. So your event is sent, but not handeled.

    In addition, I don't think you can deactivate an application by sending the ApplicationDeactivate event. The event just raises when you've been deactivated. I'm note even sure if an application can deactivate itself.



  • actually I want to capture user action of click on dock icon.

    I found the even function in Application class will receive a message.

    @
    bool QQApplication::event(QEvent * event)
    {
    if(event->type() == QEvent::ApplicationActivate){
    ...
    }
    }
    @

    but the windows of my app are hidden instead of close.

    so when all windows close user click on the dock icon the app dosen't emit a activate even.

    So I want to sendevent() send a ApplicationDeactivate event when all windows are close.

    How can I do that?

    [quote author="Lukas Geyer" date="1322132584"]sendEvent() returns the value that was returned from the event handler. QCoreApplication has no (default) implementation for ApplicationActivate and ApplicationDeactivate, thus false is returned. So your event is sent, but not handeled.

    In addition, I don't think you can deactivate an application by sending the ApplicationDeactivate event. The event just raises when you've been deactivated. I'm note even sure if an application can deactivate itself.[/quote]

    [EDIT: code formatting, Volker]



  • So you basically just want the default behaviour on Mac OS where clicking the close button hides the application instead of closing it and a click to the dock icon should restore it, right?

    Well, I'm not a Qt on Mac OS expert but i think you'll have to revert to some platform-specific code (or at least macEvent() resp. macEventFilter()) to act accordingly.

    As a sidenote: more and more applications on Mac OS seem to act like Qt applications do by default - by closing the application when the close button is clicked.



  • The application deactivate signal is sent, when the application is deactivated - quel surprise! Deactivation works by activating another application (you can see it by the menu bar changing the applications's name). To my knowledge and own user experience this is only possible by terminating the application or by using explicit means like the dock, the app chooser at cmd-tab, spaces or expose.

    If you close the last window of an app like iCal, iTunes or the Finder that application is still the current app (check the menu bar!).

    I never heard of an application that can "give away" its active state to another application. Even if it was possible, I as a user would be heavily annoyed by such behavior and I would most probably purge such an app from my disk.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.