Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved QML: Image not showing from resource file

    QML and Qt Quick
    3
    7
    47
    Loading More Posts
    • 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
      MyNameIsRichard last edited by

      With a very simple project images from a resource file are not showing on the controls.

      QtCreator information

      Qt Creator 11.0.3
      Based on Qt 6.4.3 (GCC 10.3.1 20210422 (Red Hat 10.3.1-1), x86_64)
      
      Built on Sep 27 2023 06:36:40
      
      From revision 68359f96a9
      

      My Main.qml

      import QtQuick
      import QtQuick.Window
      import QtQuick.Controls
      import QtQuick.Layouts
      
      ApplicationWindow {
          width: 640
          height: 480
          visible: true
          title: qsTr("Daily Pics")
      
          header: ToolBar {
              height: 50
      
              RowLayout {
                  spacing: 20
                  anchors.fill: parent
      
                  ToolButton {
                      icon.source: "qrc:///images/drawer.png"
                  }
              }
          }
      }
      

      My resource.qrc

      <RCC>
          <qresource prefix="/">
              <file>images/drawer.png</file>
          </qresource>
      </RCC>
      
      

      The image exists in the images folder

      J.Hilk 1 Reply Last reply Reply Quote 0
      • J.Hilk
        J.Hilk Moderators @MyNameIsRichard last edited by

        @MyNameIsRichard try less slashes :D or more simply:

        right click on the drawer.png in your projects view, select: copy url,
        paste that url as source, profit

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

        Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        M 1 Reply Last reply Reply Quote 0
        • M
          MyNameIsRichard @J.Hilk last edited by

          @J-Hilk What I found online showed three slashes so today I learned about copy URL. It made no difference though, the image is still not showing. I even deleted the build directory, just in case...

          J.Hilk 1 Reply Last reply Reply Quote 0
          • J.Hilk
            J.Hilk Moderators @MyNameIsRichard last edited by

            @MyNameIsRichard I think you have to give your button a height and width or use the Layout.preferredWidth properties

            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

            Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            M 1 Reply Last reply Reply Quote 0
            • M
              MyNameIsRichard @J.Hilk last edited by

              @J-Hilk Still no difference I'm afraid. The button's hover effect shows up and it's clickable, just no image :(

              1 Reply Last reply Reply Quote 0
              • Markkyboy
                Markkyboy last edited by

                I note you are using QT6 ( I gave up when I couldn't even get a drop shadow to show on a rectangle), but along the way, I found this video; https://www.youtube.com/watch?v=UDCRQiMMiZ4 this helped me at least get images to display.

                Don't just sit there standing around, pick up a shovel and sweep up!

                I live by the sea, not in it.

                M 1 Reply Last reply Reply Quote 0
                • Topic has been marked as solved  M MyNameIsRichard 
                • M
                  MyNameIsRichard @Markkyboy last edited by

                  @Markkyboy That provided the solution.

                  Add the following to CMakeLists.txt

                  set(CMAKE_AUTOMOC ON)
                  set(CMAKE_AUTORCC ON)
                  
                  1 Reply Last reply Reply Quote 1
                  • First post
                    Last post