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. How the position offsets do not return to initial values after pressing the button?
Forum Updated to NodeBB v4.3 + New Features

How the position offsets do not return to initial values after pressing the button?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 116 Views
  • 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
    morita
    wrote on last edited by
    #1

    Hello.

    I want to make a virtual joystick. When I pressed a circle button, I try to change positions using mouseX and mouseY
    of MouseArea. So I changed the CenterOffsets of the button. But I have a problem that the position offsets return to initial values.
    The initial values are (0,0). That is why I see the button is swung when I pressed it every time.
    Do you have any solutions to how the position offsets do not return to initial values after pressing the button?

    The following is my code.

    import QtQuick 2.1
    import QtQuick.Controls 2.1
    import "../components"
    Rectangle {
    id: root
    width:150
    height:150
    color: "green"

    signal joystick_moved(double x, double y);
    
    Image {
        id: joystick
    
        source: "./../assets/joystick_base.png"
        anchors.centerIn: root
    }
    
    Rectangle {
        id: thumb
        anchors.centerIn: parent
    
        width:50
        height:50
        radius: width/2
        border.width: 3
        anchors.verticalCenterOffset: 0
        anchors.horizontalCenterOffset: 0
    
        MouseArea {
            id: mouse
             anchors.fill: thumb
            property int mcx : mouseX
            property int mcy : mouseY
    
            onPositionChanged: {
                thumb.anchors.horizontalCenterOffset = mouseX
                thumb.anchors.verticalCenterOffset = mouseY
                console.log("mouseX:" + mouseX + "mouseY:" + mouseY)
                console.log("mcx:" + thumb.anchors.horizontalCenterOffset
                            + "mcy:" + thumb.anchors.verticalCenterOffset)
            }
        }
    
    }
    

    }

    1 Reply Last reply
    0

    • Login

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