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

118
Visualizações
Why does following code starts misbehaving if mouse is clicked few times?

Problem: Following is a qt qml program. I am using qt6 version. on repeated mouse clicks, program starts behaving incorrectly. The rotation on each start after mouse is clicked, goes on with reduced speed. What is causing bug in this code, which seems perfect to me.

Following is a qt qml program. I am using qt6 version. on repeated mouse clicks, program starts behaving incorrectly. The rotation on each start after mouse is clicked, goes on with reduced speed. What is causing bug in this code, which seems perfect to me.

import QtQuick

Window {
    width: Screen.width
    height: Screen.height
    visible: true
    title: qsTr("Firki")    
    property int globalFrom: 0

    Image {
        anchors.fill: parent
        source: "qrc:/images/background.png"

        Image {
            anchors.bottom: parent.bottom
            anchors.horizontalCenter: parent.horizontalCenter
            height: parent.height / 2
            source: "qrc:/images/pole.png"
        }

        Image {
            id: firki
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.verticalCenter: parent.verticalCenter
            source: "qrc:/images/pinwheel.png"

            RotationAnimation on rotation {
                id: rotatefirki
                loops: rotateblurredfirki.loops
                duration: rotateblurredfirki.duration
                from: rotateblurredfirki.from
                to: rotateblurredfirki.to
                running: rotateblurredfirki.running
            }
        }

        Image {
            id: blurredfirki
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.verticalCenter: parent.verticalCenter
            source: "qrc:/images/blur.png"
            opacity: 0

            RotationAnimation on rotation {
                id: rotateblurredfirki
                loops: Animation.Infinite
                duration: 1000
                from: globalFrom
                to: 360
                running: false
            }
        }
    }

    MouseArea {
        anchors.fill: parent

        onClicked: {
            if(!rotateblurredfirki.running)
            {
                rotateblurredfirki.restart()
                blurredfirki.opacity = 1
            }
            else
            {
                rotateblurredfirki.stop()
                globalFrom = Math.floor(blurredfirki.rotation)
                blurredfirki.opacity = 0
            }
        }
    }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think the paused property will be useful to you here. First bind rotatefirki's paused property to rotateblurredfirki's.

    RotationAnimation on rotation {
        id: rotatefirki
        ...
        paused: rotateblurredfirki.paused
    }

Then change your mouse click handler to toggle the paused the property:

    MouseArea {
        anchors.fill: parent

        onClicked: {
            if(!rotateblurredfirki.running)
            {
                // Not running, so start the animation
                rotateblurredfirki.restart()
            }
            else
            {
                // Keep it running, but pause it
                rotateblurredfirki.paused = !rotateblurredfirki.paused
                blurredfirki.opacity = 1 - blurredfirki.opacity
            }
        }
    }
about 4 years ago · Juan Pablo Isaza Relatório
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