D
D
DeMON_L2020-12-24 18:37:42
Qt
DeMON_L, 2020-12-24 18:37:42

How to autocomplete in QML for objects of type QtObject?

1) For example, there is a file with an application design system from UI to qml:
file Design.qml

QtObject {
    id: designSystem

    property QtObject colors: QtObject {
        property color buttonColor: "#FF4F12"
        property color backgroundColor: "#00AAE7"
        property color tileColor: "#5DC600"
        ...
    }

    property QtObject size: QtObject {
    ....

    }
}


2) Register this singleTon:

qmlRegisterSingletonType(QUrl("qrc:/DesignSystem.qml"), "app.design", 1, 0, "Design");


3) Somewhere in other code use of this component:
file Button.qml

import app.design 1.0

Rectangle {
    id: button

    color: Design.color.buttonColor    // Вопрос к данной строчке
}


So the question is: how to make the QtCreator editor auto-complete the properties of the Design and color components, and so on?
Because at the moment the editor sees only the parent Design component itself, all other properties have to be entered manually, as in a regular notepad

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jacob E, 2020-12-24
@Zifix

QtObject {
property QtObject colors: QtObject {

You somehow hid it all too deeply. We would just make a property set in the root object, and call it as Design.buttonColor - it would be auto-completion, the code is shorter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question