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. Create Rectangle on Click?
Forum Updated to NodeBB v4.3 + New Features

Create Rectangle on Click?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 3 Posters 1.9k 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.
  • M Offline
    M Offline
    maxwell31
    wrote on last edited by
    #1

    Hi,

    I am creating a plotting component, and want to be able to add Vertical Lines (marks) to my plot on a mouse click, sth. like this:

            Rectangle{
                id: recMark
                border.width: 0
                width: 2
                height: parent.height
                y: 0
                z: 5
                color: "red"
                opacity: 0.3
                visible: true
                MouseArea {
                    anchors.fill: parent
                    drag.target: recMark
                    drag.axis: Drag.XAxis
    
                }
            }
    
            MouseArea {
                anchors.fill: parent
                acceptedButtons: Qt.LeftButton
                onPressed: {
                    if(mouse.modifiers& Qt.ShiftModifier) {
                        recMark.x = mouseX-recMark.width/2;
                        recMark.visible=true;
                    }
    

    This is basically what I want, for one Line. How would I need to do it, if I want to create a new Rectangle Item every time I click?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Use Qt.createComponent(), for example. Here are the docs: link.

      (Z(:^

      1 Reply Last reply
      2
      • ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by ODБOï
        #3

        @maxwell31 hello,

        1st google suggestion for : "qt create component"

        http://doc.qt.io/qt-5/qtqml-javascript-dynamicobjectcreation.html

        or simply

        Row{
         Repeater{
          id:r
           model:0
           YourMark{
           
          }
        }
        }
        //-
        MouseArea{
        ...
        onClicked: r.model+=1
        }
        //-
        
        1 Reply Last reply
        1

        • Login

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