Create Rectangle on Click?
Solved
QML and Qt Quick
-
wrote on 6 Apr 2018, 16:08 last edited by
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?
-
Use Qt.createComponent(), for example. Here are the docs: link.
-
wrote on 6 Apr 2018, 22:09 last edited by ODБOï 4 Jun 2018, 22:15
@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/3