#[derive(QModelItem)]Expand description
Derive macro that generates a QModelItem implementation.
Applying this macro to a struct allows it to be used inside QVec<T>
and exposed to QML, where it can be visualized with various views. The
delegates within the view are able to read and write to the struct
through the roles.
§Roles
- Named Field Struct: The generated roles will match the names of the
fileds (e.g.,
name,age, …). Fields nameddisplay,decoration,edit,toolTip,statusTip, orwhatsThisare recognized as default roles as used in Qt’s default delegates. - Tuple Structs: The generated roles are
"_0","_1","_2", …
§Type requirements
All fields must be convertible to and from QVariant.
§Example
ⓘ
#[derive(QModelItem)]
struct Person {
name: String, // role "name"
age: u32, // role "age"
}
#[derive(QModelItem)]
struct Pair(i32, String); // roles "_0", "_1"