Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [QML] What can i use to allow adding images on clic ?
Forum Update on Tuesday, May 27th 2025

[QML] What can i use to allow adding images on clic ?

Scheduled Pinned Locked Moved General and Desktop
qmlimagec++clic
6 Posts 2 Posters 1.9k Views 2 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.
  • K Offline
    K Offline
    Kaxu
    wrote on 22 Apr 2015, 08:49 last edited by Kaxu
    #1

    Hi,

    I'm developping a software where the user has a map in front of him (which is an image), and he can click it and it automatically add "markers" on the map where it has been clicked. Each click on the map generate a new marker, and the user can eventually drag them or delete them.
    The "markers" are simple images too.

    I'd like to have access to the coordinates of each marker, in order to allow the user to modify them.

    What kind of object can i use to do so ( preferably in QML ) ?
    For the moment i'm using Qt.createComponent("marker.qml"); which allow to create, drag and delete items, but it doesn't do the trick since i'm unable to access the coordinates of each marker one by one.

    P 1 Reply Last reply 22 Apr 2015, 09:34
    0
    • K Kaxu
      22 Apr 2015, 08:49

      Hi,

      I'm developping a software where the user has a map in front of him (which is an image), and he can click it and it automatically add "markers" on the map where it has been clicked. Each click on the map generate a new marker, and the user can eventually drag them or delete them.
      The "markers" are simple images too.

      I'd like to have access to the coordinates of each marker, in order to allow the user to modify them.

      What kind of object can i use to do so ( preferably in QML ) ?
      For the moment i'm using Qt.createComponent("marker.qml"); which allow to create, drag and delete items, but it doesn't do the trick since i'm unable to access the coordinates of each marker one by one.

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 22 Apr 2015, 09:34 last edited by
      #2

      Hi @Kaxu and Welcome
      I find following two ways to do it:

      • Maintain a list to store the create objects
          property var listObj: []
          ...
          var comp  = Qt.createComponent("Marker.qml")
          var obj = comp.createObject(rect,{"x": mouseX, "y": mouseY, "objectName": "marker"}) //rect = parent
          listObj.push(obj)
      
      
      Then you can just iterate the list and access the Items as well as its properties.
      
      for(var item in listObj)
          console.log(listObj[item].x, listObj[item].y)
      
      • Iterate the children of parent of Marker.qml object.
         var comp  = Qt.createComponent("Marker.qml")
         var obj = comp.createObject(rect,{"x": mouseX, "y": mouseY, "objectName": "marker"})
         
         ...
         
         for(var item in rect.children) {
              if(rect.children[item].objectName==="marker")
                   console.log(rect.children[item].x, rect.children[item].y)
         }
      

      Hope I understood you correctly :)

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kaxu
        wrote on 22 Apr 2015, 09:49 last edited by p3c0
        #3

        I fact, i have to take the coordinates from a database, so i have them in the C++ part.
        What i'd like to know is if there is an object i can use where i could do something like this :

        void getCoordinates() {
        // Connecting to DB
        // Getting every x and y from each row
        
          for (row=0;row<db.rowCount();row++) {
                 createMarker(x,y);
          }
        }
        

        How can i do such a thing? Which QItem should i use ?

        P 2 Replies Last reply 22 Apr 2015, 09:57
        0
        • K Kaxu
          22 Apr 2015, 09:49

          I fact, i have to take the coordinates from a database, so i have them in the C++ part.
          What i'd like to know is if there is an object i can use where i could do something like this :

          void getCoordinates() {
          // Connecting to DB
          // Getting every x and y from each row
          
            for (row=0;row<db.rowCount();row++) {
                   createMarker(x,y);
            }
          }
          

          How can i do such a thing? Which QItem should i use ?

          P Offline
          P Offline
          p3c0
          Moderators
          wrote on 22 Apr 2015, 09:57 last edited by p3c0
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • K Offline
            K Offline
            Kaxu
            wrote on 22 Apr 2015, 10:03 last edited by
            #5

            @p3c0 this is not c++ code... And i can't access the database in Javascript.

            1 Reply Last reply
            0
            • K Kaxu
              22 Apr 2015, 09:49

              I fact, i have to take the coordinates from a database, so i have them in the C++ part.
              What i'd like to know is if there is an object i can use where i could do something like this :

              void getCoordinates() {
              // Connecting to DB
              // Getting every x and y from each row
              
                for (row=0;row<db.rowCount();row++) {
                       createMarker(x,y);
                }
              }
              

              How can i do such a thing? Which QItem should i use ?

              P Offline
              P Offline
              p3c0
              Moderators
              wrote on 22 Apr 2015, 10:04 last edited by p3c0
              #6

              @Kaxu From C++ side you can use QQmlComponent. After creation cast it to QQuickItem and then set x and y coordinates using setProperty. Follow the example on that link. Then after creating

              QObject *myObject = component.create();
              QQuickItem *item = qobject_cast<QQuickItem*>(myObject);
              item.setProperty("x",x); //x and y which you already have.
              item.setProperty("y",y);
              
              1 Reply Last reply
              0

              1/6

              22 Apr 2015, 08:49

              • Login

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