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 access a specific component

How to access a specific component

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

    Hi
    I wrote a litte qml application which will create an Object of a Component every time a button is clicked.

    import QtQuick 2.6
    import QtQuick.Window 2.2
    Window {
        id: mainWindow
        visible: true
        width: 1280
        height: 720
    
        property int idNumberCounter: 1
    
        Component
        {
         id: testComponent
    
            Rectangle
          {
               id: rectangleMade
               property int idNumber: 0
                width: 100
                height: 100
                x: 100*idNumber
                 border.color: "blue"
        }
    }
    //The button for creating 
       Rectangle
        {
            id: buttonMakeRectangle
            color: "red"
            width: 50
            height: 50
            MouseArea
            {
                anchors.fill: parent
                onClicked:
                {
                    testComponent.createObject(mainWindow,{idNumber:mainWindow.idNumberCounter});
                     mainWindow.idNumberCounter++;
                }
            }
        }
    }
    

    What I would like to do now is to have a second button, which will e.g. change the x-Value of the rectangle with the idNumber=3 (if available).

    Is there a way to access a specific component?

    FYI: Adding a MouseArea to the "rectagleMade" and simply perfom the work there is not possible, because in the real application this rectangles are controlled via dBus from another application. (it will be a windowing manager with QtWayland)

    Thanks for help

    Thorsten

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @outdoor_guy Check if you can add these newly created objects in a property variant and then later access it.

      157

      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