Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
QML Cree un componente dinámicamente presionando el mouse y arrástrelo a una nueva ubicación

¡Buenos días!

Hay un elemento al hacer clic en el que se crea un nuevo elemento: main.qml

 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") Rectangle { id: black x: 200 y: 200 width: 50 height: 50 color: "black" MouseArea { anchors.fill: parent onPressed: { var pos = mapToItem(black.parent, mouse.x, mouse.y) createNew(pos) } function createNew(pos) { var comp = Qt.createComponent("qrc:/src/qml/NewElement.qml"); if (comp.status !== Component.Ready) { console.log("Error creating component"); } var link = comp.createObject(black.parent, { x: pos.x, y: pos.y, z:100}); if (link === null) { console.log("Error creating object"); } return link } } } }

Hay un nuevo elemento que se puede arrastrar: New Element.qml

 Item { id: red width: 30 height: 30 Rectangle { anchors.fill: parent color: "red" } MouseArea { anchors.fill: parent drag.target: red drag.axis: Drag.XandYAxis } }

Después de crear el elemento, debe volver a hacer clic en el elemento para arrastrarlo. Pregunta: ¿Cómo hacer que después de crear un elemento, se pueda arrastrar inmediatamente (con el botón del mouse presionado)

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Puede usar las propiedades adjuntas de Drag.* , algo como esto:

 Rectangle { id: container anchors.fill: parent color: "orange" Component { id: itemComponent Rectangle { width: 50 height: 50 border.color: "grey" radius: 5 color: "lightblue" } } MouseArea { id: mouseArea anchors.fill: parent onPressed: (mouse)=> { addItem(mouse.x, mouse.y); } onReleased: { Drag.active = false; } function addItem(x, y) { var obj = itemComponent.createObject(container, { x: x - 25, y: y - 25 }); mouseArea.drag.target = obj; Drag.active = true; } } }
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!