qt - QSystemTrayIcon notification message with custom icon -


qsystemtrayicon has function :

void showmessage(const qstring &title, const qstring &msg, messageicon icon = information, int msecs = 10000);

is there way change custom icon , example -

void showiconmessage(const qstring &title, const qstring &msg, qicon icon = qicon(), int msecs = 10000);

without modifying qt sources

i know showmessage (d instance of qsystemtrayiconprivate , called q_d(qsystemtrayicon) macro)

void qsystemtrayicon::showmessage(const qstring& title, const qstring& msg,                             qsystemtrayicon::messageicon icon, int msecs) {     q_d(qsystemtrayicon);     if (d->visible)         d->showmessage_sys(title, msg, icon, msecs); } 

calls showmessage_sys qsystemtrayiconprivate in turn magic icon happens:

void qsystemtrayiconprivate::showmessage_sys(const qstring &message,                                              const qstring &title,                                              qsystemtrayicon::messageicon icon,                                              int msecs) {     if (!qpa_sys)         return;      qicon notificationicon;     switch (icon) {     case qsystemtrayicon::information:         notificationicon = qapplication::style()-   >standardicon(qstyle::sp_messageboxinformation);         break;     case qsystemtrayicon::warning:         notificationicon = qapplication::style()->standardicon(qstyle::sp_messageboxwarning);         break;     case qsystemtrayicon::critical:         notificationicon = qapplication::style()->standardicon(qstyle::sp_messageboxcritical);         break;     default:         break;     }     qpa_sys->showmessage(message, title, notificationicon,                      static_cast<qplatformsystemtrayicon::messageicon>(icon), msecs); } 

now, seems, need re-implement these 2 functions in 2 classes , i'm ready go, but.. seems qsystemtrayicon closely tied qsystemtrayiconprivate. instance of qsystemtrayiconprivate created in qsystemtrayicon constructor (which can't change if plan create classes inherit both qsystemtrayicon , qsystemtrayiconprivate , re-implement showmessage functions):

qsystemtrayicon::qsystemtrayicon(qobject *parent) : qobject(*new qsystemtrayiconprivate(), parent) { }  qsystemtrayicon::qsystemtrayicon(const qicon &icon, qobject *parent) : qobject(*new qsystemtrayiconprivate(), parent) {     seticon(icon); } 

so there missing? or there way show notification message custom icon?

what try (not sure if work system tray) same described in this answer , override sp_messageboxwarning / sp_messageboxcritical / sp_messageboxinformation icons, said i'm not sure if system tray uses downscaled version of message box icons or if system tray icons separate. in case of latter, guess have patch qt sources, maybe add new item qsystemtrayicon , patch switch call function provided return needed icon. like:

void qsystemtrayiconprivate::showmessage_sys(const qstring &message,                                              const qstring &title,                                              qsystemtrayicon::messageicon icon,                                              int msecs) {     if (!qpa_sys)         return;      qicon notificationicon;     switch (icon) {     case qsystemtrayicon::information:         notificationicon = qapplication::style()-   >standardicon(qstyle::sp_messageboxinformation);         break;     case qsystemtrayicon::warning:         notificationicon = qapplication::style()->standardicon(qstyle::sp_messageboxwarning);         break;     case qsystemtrayicon::critical:         notificationicon = qapplication::style()->standardicon(qstyle::sp_messageboxcritical);         break;     case qsystemtrayicon::custom:         // call function fetch needed icon , assign notificationicon         break;     default:         break;     }     qpa_sys->showmessage(message, title, notificationicon,                      static_cast<qplatformsystemtrayicon::messageicon>(icon), msecs); } 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -