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. QML SystemTrayIcon icon from QML module not showing
Forum Updated to NodeBB v4.3 + New Features

QML SystemTrayIcon icon from QML module not showing

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 609 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.
  • M Offline
    M Offline
    MaxL
    wrote on last edited by
    #1

    Hello.

    I am facing a bug that I cannot understand on macOS using Qt 6.7.2 when trying to display an icon for the SystemTrayIcon QML widget.

    This is the Main.qml loaded with engine.loadFromModule("qmlModule", "Main"); :

    SystemTrayIcon {
        property Window window: Window {
            visible: true
            width: 400
            height: 400
           Image {
                 anchors.fill: parent
                 source: "assets/icons/bad.png"
          }
       }
        icon.source: "assets/icons/bad.png"
        visible: true
    }
    

    For some reasons, the icon.source does not work, nothing is visible in the system tray while there is no problem in the Image with the same asset.

    Assets are added to the QML module with the RESSOURCES option of qt_add_qml_module CMake function.

    Maybe it is also linked but the showMessage from the SystemTrayIcon also does not work.

    I have tried the Qt sample project Systray and it works well (icon and showMessage) but it is using QWidget.

    Any idea on what is going on ?
    Thanks.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #4

      Then check with qrc:/myproject/qml/assets/icons/bad.png . icon.source is a url so it requires a scheme hence the qrc:/. It should be the same for Image though.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        I haven't used that yet but intuitively since you mention resources, I would think that you need to prefix the path with qrc:/.

        Both path should then be qrc:/assets/icons/bad.png.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MaxL
          wrote on last edited by
          #3

          That is what I thought at first.

          But using qt_add_qml_module and especially the RESOURCE argument it will create a qrc file with aliases.

          For instance it creates this qrc file:

          <RCC>
            <qresource prefix="/myproject/">
              <file alias="qml/assets/icons/bad.png">`project_path`/qml/assets/icons/bad.png</file>       
            </qresource>
          </RCC>
          

          If I follow how resource file works and especially prefixes and alliases, I should be able to reference the file with :/<prefix>/<file alias>.

          Therefore, in my case, I should be able to use :/myproject/qml/assets/icons/bad.png but it does not work. It only work with assets/icons/bad.png and only for the Image, not the SystemTrayIcon. As I am writing this, I think I understand why it works that way (at least for the Image) as it is a relative path pointing to the "local resource".

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by SGaist
            #4

            Then check with qrc:/myproject/qml/assets/icons/bad.png . icon.source is a url so it requires a scheme hence the qrc:/. It should be the same for Image though.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • M MaxL has marked this topic as solved on
            • M Offline
              M Offline
              MaxL
              wrote on last edited by MaxL
              #5

              Thanks it works that way.
              I thought I tried this way but maybe I made a mistake somewhere.
              Anyway it works for all of the component (Image, SystemTrayIcon and MenuItem)

              1 Reply Last reply
              0

              • Login

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