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 do I load multiple images to be accessed by a Canvas as an array in QML
Forum Updated to NodeBB v4.3 + New Features

How do I load multiple images to be accessed by a Canvas as an array in QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 237 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.
  • A Offline
    A Offline
    AI_Messiah
    wrote on last edited by
    #1

    This is what I have tried doing:

    import QtQuick 2.12
    import QtQuick.Window 2.12
    
    Window {
        width: 1024
        height: 768
        visible: true
        title: qsTr("Hello World")
        Canvas{
            id: mycanvas
            anchors.centerIn: parent
            width: 500
            height: 500
            Component.onCompleted:  {
                var myfiles = ["/images/test0.png","/images/test1.png","/images/test2.png","/images/test3.png"]
                var oneEl = ""
                for (var i=0;i<4;i++){
                    oneEl = myfiles[i]
                    loadImage(mycanvas.oneEl);
                }
            }
    
            //This part I can play with later
            onPaint: {
                var ctx = getContext("2d");
                ctx.fillStyle = Qt.rgba(1, 0, 0, 1);
                ctx.drawImage()
            }
        }
    
    }
    
    

    When I actually need more images I can change the way I access their names. I'm thinking of converting a number to a hexadecimal string to access the files which I will have to figure out how to do

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by fcarney
      #2

      @AI_Messiah said in How do I load multiple images to be accessed by a Canvas as an array in QML:

      loadImage(mycanvas.oneEl);

      Shouldn't this be loadImage(oneEl)? oneEl is not a property of mycanvas.

      Edit: isImageLoaded will tell you if its loaded. https://doc.qt.io/qt-5/qml-qtquick-canvas.html#loadImage-method

      C++ is a perfectly valid school of magic.

      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