Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to set icon of showMessage function using at SystemTray QML type?

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

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sazus
    wrote on last edited by
    #1

    Hi all,

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

    void showMessage(string title, string message, MessageIcon icon, int msecs)
    (http://doc.qt.io/qt-5/qml-qt-labs-platform-systemtrayicon.html)

    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)
    (http://doc.qt.io/qt-5/qsystemtrayicon.html)

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

    Gojir4G 1 Reply Last reply
    0
    • S sazus

      Hi all,

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

      void showMessage(string title, string message, MessageIcon icon, int msecs)
      (http://doc.qt.io/qt-5/qml-qt-labs-platform-systemtrayicon.html)

      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)
      (http://doc.qt.io/qt-5/qsystemtrayicon.html)

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

      Gojir4G Offline
      Gojir4G Offline
      Gojir4
      wrote on last edited by
      #2

      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)
      
      1 Reply Last reply
      2
      • Gojir4G Offline
        Gojir4G Offline
        Gojir4
        wrote on last edited by Gojir4
        #3

        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

        1 Reply Last reply
        2
        • S Offline
          S Offline
          sazus
          wrote on last edited by
          #4

          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,
          NoIcon、Information、Warning、Critical

          <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");
                  break;
              case Warning:
                  m_attentionIconName = QStringLiteral("dialog-warning");
                  break;
              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");
                  break;
              default:
                  m_attentionIconName.clear();
                  break;
              }
          

          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.

          <"SystemTrayIcon.Information">
          0_1544416962342_Info.png

          <"SystemTrayIcon.Warning">
          0_1544417044311_warnning.png

          <"SystemTrayIcon.Critical">
          0_1544417067698_error.png

          <"SystemTrayIcon.NoIcon">
          0_1544417095345_NoIcon.png

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

          Thanks Gojir4!

          1 Reply Last reply
          3

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved