Run-time Set OSX Dock Icon

  • I'm attempting to set the Dock Icon for my application dynamically via the call


    The documentation ( says:
    "The application icon, typically displayed in the application dock area, is set by calling QWindow::setWindowIcon() on a window. It is possible that the program could appear in the application dock area before the function call, in which case a default icon will appear during the bouncing animation."

    However it seems to have no effect on the Dock.

    The call does alter the Window's Icon (top left of the Window).

    Does anyone have any experience achieving this? Is the call correct? Are there timing restrictions (ie. before show())? Is my Icon invalid for this case somehow?

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    macOS dock is a different beast in regard of the other OSs. You might have to do a bit of native coding for that.

    Take a look at the Apple documentation for Dock.

  • Thanks for the link.

    I was able to achieve the desired behavior by also using the following code:

     NSImage * icon;
    [NSApp setApplicationIconImage: icon];
    [[NSApp dockTile] display];

    In my opinion, the Qt document is misleading / incorrect on the behavior of that API for OSX.
    Hopefully others can benefit from my troubles though.

  • Lifetime Qt Champion

    The documentation might indeed benefit from a clarification about that.

    Please open a report against qtbase for the documentation on the bug report system.

    You can even do a submission to improve the documentation yourself.

Log in to reply