O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – Dragging an item around

Create a new Qt Quick Application - Empty project. Edit the main.qml file to add a circle to the window:

Rectangle {
    id: circle
    width: 60; height: width
    radius: width / 2
    color: "red"
} 

Next, add a MouseArea to the circle and use its drag property to enable moving the circle by touch (or mouse):

Rectangle {
    //...
    MouseArea {
        anchors.fill: parent
        drag.target: circle
    }
}

Then, you can start the application and begin moving the circle around.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required