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. How to add rectangle in qml dynamically?
Qt 6.11 is out! See what's new in the release blog

How to add rectangle in qml dynamically?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.5k Views
  • 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.
  • BharathiB Offline
    BharathiB Offline
    Bharathi
    wrote on last edited by
    #1

    How add rectangle dynamically with different sizes in qml??I just try with repeater but I can't edit sizes in repeater.

    D 1 Reply Last reply
    1
    • BharathiB Bharathi

      How add rectangle dynamically with different sizes in qml??I just try with repeater but I can't edit sizes in repeater.

      D Offline
      D Offline
      Devopia53
      wrote on last edited by
      #2

      @Bharathi

      Hi.

      See the following example.

      import QtQuick 2.5
      import QtQuick.Window 2.2
      
      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          MouseArea {
              anchors.fill: parent
              onClicked: {
                  var newObject = Qt.createQmlObject('import QtQuick 2.5; Rectangle {color: "red";}', parent);
                  newObject.x = mouseX;
                  newObject.y = mouseY;
                  newObject.width = Math.random()*100+10;
                  newObject.height = Math.random()*100+10;
              }
          }
      
          Text {
              text: qsTr("Hello World")
              anchors.centerIn: parent
          }
      }
      
      
      1 Reply Last reply
      4
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
        wrote on last edited by
        #3

        You can also try with Loader or Qt.CreateComponent example given in the Assistant.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        https://www.pthinks.com

        1 Reply Last reply
        5

        • Login

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