Label in Mac dock icon [Solved]



  • Hi all,

    I'm not sure whether my previous research on this was for Java Swing or Qt, but I haven't been able to find any usable results right now:

    Is it possible to add a (1-2 digit) label to a dock icon on Mac OS with Qt? I know it's possible using pure Obj. C, but is there a specific interface in Qt that does just that?

    Thanks in advance.



  • The silence tells everything I guess. Oh well. Even though my objective C skills are below zero, I managed to put together a simple wrapper class after a bit of googling and experimentation:

    DockIconLabel.h:

    @#ifndef DOCKICONLABEL_H
    #define DOCKICONLABEL_H

    #include <QString>

    class DockIconLabel
    {
    public:
    static void setValue(const QString &val);
    };

    #endif // DOCKICONLABEL_H@

    DockIconLabel.mm:

    @#include "DockIconLabel.h"
    #import "Foundation/NSAutoreleasePool.h"
    #import "AppKit/NSApplication.h"

    void DockIconLabel::setValue(const QString &val)
    {
    const QByteArray utf8 = val.toUtf8();
    const char* cString = utf8.constData();
    [[[NSApplication sharedApplication] dockTile] setBadgeLabel:[[NSString alloc] initWithUTF8String:cString]];
    }

    @


  • Lifetime Qt Champion

    Na, you were just quicker to find the solution :)

    Thanks for sharing !


  • Lifetime Qt Champion

    Hi again,

    There are now helper functions in qtmacextras to do that



  • Sounds good, thanks for info!


Log in to reply
 

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