Sur cette page

QtObject QML Type

Un type QML de base. En savoir plus…

Import Statement: import QtQml
In C++: QObject
Inherited By:
135 types

AbstractButton, Action, ActionGroup, AllOfFilter, AnimatedImage, AnimatedSprite, AnyOfFilter, BorderImage, BusyIndicator, Button, ButtonGroup, Calendar, Canvas, CheckBox, CheckDelegate, ColorGroup, ColorOpacityAnimation, Column, ColumnLayout, ComboBox, Container, Control, DayOfWeekRow, DelayButton, Dial, Dialog, DialogButtonBox, DoubleSpinBox, Drawer, DropArea, EllipseShape, FilterBase, FlexboxLayout, Flickable, Flipable, Flow, FocusScope, Frame, FunctionFilter, FunctionSorter, Grid, GridLayout, GridView, GroupBox, HorizontalHeaderView, HorizontalHeaderViewDelegate, Image, ImageParticle, Item, ItemDelegate, ItemGrabResult, ItemParticle, Label, LayoutItemProxy, ListView, Loader, MaskShape, Menu, MenuBar, MenuBarItem, MenuItem, MenuSeparator, MonthGrid, MouseArea, MultiEffect, MultiPointTouchArea, Overlay, Page, PageIndicator, Palette, Pane, ParticlePainter, PathView, PinchArea, Popup, ProgressBar, RadioButton, RadioDelegate, RangeFilter, RangeSlider, Rectangle, RectangularShadow, RegExpFilter, Repeater, RoleFilter, RoleSorter, RoundButton, Row, RowLayout, ScrollBar, ScrollIndicator, ScrollView, SearchField, SelectionRectangle, Settings, ShaderEffect, ShaderEffectSource, Shape, Slider, Sorter, SpinBox, SplitHandle, SplitView, SpriteSequence, StackLayout, StackView, StandardPaths, StringSorter, SwipeDelegate, SwipeView, Switch, SwitchDelegate, SystemInformation, TabBar, TabButton, TableView, TableViewDelegate, Text, TextArea, TextEdit, TextField, TextInput, ToolBar, ToolButton, ToolSeparator, ToolTip, TreeView, TreeViewDelegate, Tumbler, ValueFilter, VectorImage, VerticalHeaderView, VerticalHeaderViewDelegate, WeekNumberColumn, and WindowContainer

Propriétés

Description détaillée

Le type QtObject est un élément non visuel qui ne contient que la propriété objectName.

Il peut être utile de créer un QtObject si vous avez besoin d'un type extrêmement léger pour regrouper un ensemble de propriétés personnalisées :

import QtQuick

Item {
    QtObject {
        id: attributes
        property string name
        property int size
        property variant attributes
    }

    Text { text: attributes.name }
}

Il peut également s'avérer utile pour l'intégration en C++, car il s'agit simplement d'un ` QObject` standard. Consultez la documentation d'QObject pour plus de détails.

Documentation sur les propriétés

objectName : string

Cette propriété contient la méthode ` QObject::objectName ` pour cette instance d'objet spécifique.

Cela permet à une application C++ de localiser un élément au sein d'un composant QML à l'aide de la méthode ` QObject::findChild()`. Par exemple, l'application C++ suivante localise l'élément enfant ` Rectangle ` et modifie dynamiquement sa valeur ` 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));

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.