[Development] QSystemTrayIcon label (so-called title) on OS X

Ilya Kowalewski illya.kovalevskyy at gmail.com
Mon Jan 26 00:36:16 CET 2015


Hiho there,

I was wondering how to implement support for QSystemTrayIcon label feature
we have here on OS X in Qt. For those of you who are not familiar with this
feature it's an optional text label on the right to the tray icon (
http://i.imgur.com/c98Nn08.png — red rectangle).

After a discussion with thiago and richmoore1 on IRC, I got the whole
picture of the problem. So, here we go. In Cocoa, tray icon is represented
with NSStatusItem, which is created and maintained in QCocoaSystemTrayIcon
(a child of QPlatformSystemTrayIcon interface), which is itself created
somewhere in qpa cocoa plugin. So by introducing
QCocoaSystemTrayIcon::setTitle(const
QString&) we could implement the feature itself.

The problem appears when we try to use it in public API. As you might
noticed, QSystemTrayIcon's public API has nothing to do with
QPlatformSystemTrayIcon
at all. A possible solution would be to add a public API method
QSystemTrayIcon::setTitle(const
QString&), that would actually work on OS X only, but that's not the way to
go (we don't want platform-wise features in public api, yeah?).

Then the only visible solution I can think of is adding a friendly class to
QtMacExtras, which will access private d-pointer of passed QSystemTrayIcon*
instance, in order to get its QPlatformSystemTrayIcon (later casted to
QCocoaSystemTrayIcon).

Still I am not sure what's the way to go here. So guys, what do you think?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20150125/7b0e6b87/attachment.html>


More information about the Development mailing list