QtObject QML Type

基本 QML 类型 更多...

导入语句: import QtQml 2.2
实例化: QObject
继承者:

ApplicationWindowStyle , ButtonGroup , Camera , Dialog , GraphicsApiFilter , Item , ItemGrabResult , KeyboardStyle , Menu , MenuBar , MenuItem , MenuItemGroup , MorphTarget , Popup , StackViewDelegate , StandardPaths , StencilOperationArguments , StencilTestArguments , SystemTrayIcon , TableViewColumn ,和 TumblerColumn

特性

详细描述

QtObject type is a non-visual element which contains only the objectName 特性。

It can be useful to create a QtObject if you need an extremely lightweight type to enclose a set of custom properties:

import QtQuick 2.0
Item {
    QtObject {
        id: attributes
        property string name
        property int size
        property variant attributes
    }
    Text { text: attributes.name }
}
					

It can also be useful for C++ integration, as it is just a plain QObject 。见 QObject documentation for further details.

特性文档编制

objectName : string

此特性保持 QObject::objectName for this specific object instance.

This allows a C++ application to locate an item within a QML component using the QObject::findChild() method. For example, the following C++ application locates the child Rectangle item and dynamically changes its color 值:

// MyRect.qml
import QtQuick 2.0
Item {
    width: 200; height: 200
    Rectangle {
        anchors.fill: parent
        color: "red"
        objectName: "myRect"
    }
}
					
// main.cpp
QQuickView view;
view.setSource(QUrl::fromLocalFile("MyRect.qml"));
view.show();
QQuickItem *item = view.rootObject()->findChild<QQuickItem*>("myRect");
if (item)
    item->setProperty("color", QColor(Qt::yellow));