O'Reilly logo

Qt 5 Projects by Marco Piccolino

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

Selecting an element

Looking back at the tool's screenshot and description at the beginning of this chapter, we will also recall that we might want to be able to select an element, to either move it around with the mouse input or delete it. We thus add a  selected Boolean property to the element's API, and change the element's material color from black to red to signify that the element is selected, by changing the material's ambient color property (https://doc.qt.io/qt-5.9/qml-qt3d-extras-phongmaterial.html), which provides a color overlay:

import Qt3D.Core 2.9import Qt3D.Extras 2.9Entity {    id: element    property bool selected    ...    PhongMaterial {        id: phongMaterial        ambient: selected ? Qt.rgba(255,0,0,1) : Qt.rgba(0,0,0,0)    }    ...}

If we now set ...

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