Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

214
Visualizações
QML Pass mouse events to the created element by pressing press

I have an element that creates a new element by the onPressed event, the created element has its own MouseArea with the functions onPressed and onPositionChanged. Now I have to press on the new element again to interact with it. How can I make the new element react immediately to mouse events (when the mouse button is pressed)?

import QtQuick 2.11
import QtQuick.Window 2.11

Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")

Rectangle
{
    id: start

    width: 100
    height: 100
    anchors.horizontalCenter: parent.horizontalCenter
    anchors.verticalCenter: parent.verticalCenter

    color: "red"

    Component
    {
        id: comp
        Rectangle
        {
            x: start.x
            y: start.y

            width: start.width
            height: start.height



            color: "blue"

            MouseArea
            {
                anchors.fill: parent

                onPositionChanged:
                {
                    console.log(mouse.x, mouse.y)
                    if (mouse.x < 0)
                    {
                        parent.x += mouse.x
                    }
                    if (mouse.y < 0)
                    {
                        parent.y += mouse.y
                    }
                    if (mouse.x > parent.width)
                    {
                        parent.x += mouse.x - parent.width
                    }
                    if (mouse.y > parent.height)
                    {
                        parent.y += mouse.y - parent.height
                    }
                }
            }
        }
    }

    MouseArea
    {
        anchors.fill: parent

        property Item obj

        onPressed: {
            obj = comp.createObject(start.parent);

            if (obj === null) {
                console.log("Error creating object");
            }
        }
    }

}

}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda