O'Reilly logo

Game Programming Using Qt by Lorenz Haas, Witold Wysota

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 – a simple analog clock application

Create a new Qt Quick UI project. To create a clock, we will implement a component representing the clock needle and we will use instances of that component in the actual clock element. In addition to this, we will make the clock a reusable component; therefore, we will create it in a separate file and instantiate it from within main.qml:

import QtQuick 2.0

Clock {
  id: clock
  width:  400
  height: 400
}

Then, add the new QML file to the project and call it Clock.qml. Let's start by declaring a circular clock plate:

import QtQuick 2.0 Item { id: clock property color color: "lightgray" Rectangle { id: plate anchors.centerIn: parent width: Math.min(clock.width, clock.height) height: width radius: width/2 ...

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