Important: Please read the Qt Code of Conduct -

How to set icon of showMessage function using at SystemTray QML type?

  • Hi all,

    showMessage() method of SystemTray QML type prepared as follows.

    void showMessage(string title, string message, MessageIcon icon, int msecs)

    What kind of setting value about MessageIcon?
    I tried looking for MessageIcon Type, but I couldn't understand.
    Please let me know if there is a good reference code.

    In adddition, in case of Qt Widget QSystemTrayIcon class,
    two methods are prepared as following.

    void QSystemTrayIcon::showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon icon, int millisecondsTimeoutHint);
    void QSystemTrayIcon::showMessage(const QString &title, const QString &message, const QIcon &icon, int millisecondsTimeoutHint)

    How can I configure as QIcon at QML in the same way?

  • Hi @sazus,

    This is only for specifying the type of the message, as defined in the C++ version, you can use the following values:
    NoIcon, Information, Warning, Critical

    But, if I understood correctly, the icon of the "system tray" notification is defined by the icon property.
    So I guess you can use it like that (I did not test this code)

    SystemTrayIcon {
        id: sysTray
        visible: true
        icon.source: "qrc:/images/tray-icon.png"
    //Another place in your code
    sysTray.showMessage(title, message, SystemTrayIcon.Information, 1000)

  • I did some tests, with Qt.labs.platform 1.0, and it seems that icon and msecs are ignored.
    Even in the documentation of the version 1.1, they are not providing these two arguments in the example code.

    showMessage("Message title", "Something important came up. Click this to know more.")

    This looks like a mistake in the QML documentation.

    I don't know if this behaves the same way with version 1.1

  • Thank you for your reply.

    Since then, I also investigated about Qt.labs.platform on QML module.

    Looking at the Qt library code, there was no API for users to set Icon.
    Also, It is just as Gojir4 say,
    it can set the enum type for the message type as below.
    In case of linux,

    <refer from: qtbase/src/platformsupport/themes/genericunix/dbustray/qdbustrayicon.cpp>

    void QDBusTrayIcon::showMessage(const QString &title, const QString &msg, const QIcon &icon,
                                    QPlatformSystemTrayIcon::MessageIcon iconType, int msecs)
        m_messageTitle = title;
        m_message = msg;
        m_attentionIcon = icon;
        QStringList notificationActions;
        switch (iconType) {
        case Information:
            m_attentionIconName = QStringLiteral("dialog-information");
        case Warning:
            m_attentionIconName = QStringLiteral("dialog-warning");
        case Critical:
            m_attentionIconName = QStringLiteral("dialog-error");
            // If there are actions, the desktop notification may appear as a message dialog
            // with button(s), which will interrupt the user and require a response.
            // That is an optional feature in implementations of org.freedesktop.Notifications
            notificationActions << DefaultAction << tr("OK");

    I did some tests, with Qt.labs.platform 1.0, and it seems that icon and msecs are ignored.

    the behavior of each platform differ depending on QPA, in Qt,

    In my case:

    • platform: ubuntu 16.04 LTS
    • theme: Ubuntu Gnome (defult)

    "SystemTrayIcon.Information", "SystemTrayIcon.Warning", "SystemTrayIcon.Critical" worked fine.
    However, only SystemTrayIcon.NoIcon was't able to be performed normally.





    My question was resolved, so I will close this issue.

    Thanks Gojir4!

Log in to reply