1 | //! [0]
|
---|
2 | Q_PROPERTY(type name
|
---|
3 | READ getFunction
|
---|
4 | [WRITE setFunction]
|
---|
5 | [RESET resetFunction]
|
---|
6 | [DESIGNABLE bool]
|
---|
7 | [SCRIPTABLE bool]
|
---|
8 | [STORED bool]
|
---|
9 | [USER bool])
|
---|
10 | //! [0]
|
---|
11 |
|
---|
12 |
|
---|
13 | //! [1]
|
---|
14 | Q_PROPERTY(bool focus READ hasFocus)
|
---|
15 | Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
|
---|
16 | Q_PROPERTY(QCursor cursor READ cursor WRITE setCursor RESET unsetCursor)
|
---|
17 | //! [1]
|
---|
18 |
|
---|
19 |
|
---|
20 | //! [2]
|
---|
21 | Q_PROPERTY(QDate date READ getDate WRITE setDate)
|
---|
22 | //! [2]
|
---|
23 |
|
---|
24 |
|
---|
25 | //! [3]
|
---|
26 | QPushButton *button = new QPushButton;
|
---|
27 | QObject *object = button;
|
---|
28 |
|
---|
29 | button->setDown(true);
|
---|
30 | object->setProperty("down", true);
|
---|
31 | //! [3]
|
---|
32 |
|
---|
33 |
|
---|
34 | //! [4]
|
---|
35 | QObject *object = ...
|
---|
36 | const QMetaObject *metaobject = object->metaObject();
|
---|
37 | int count = metaobject->propertyCount();
|
---|
38 | for (int i=0; i<count; ++i) {
|
---|
39 | QMetaProperty metaproperty = metaobject->property(i);
|
---|
40 | const char *name = metaproperty.name();
|
---|
41 | QVariant value = object->property(name);
|
---|
42 | ...
|
---|
43 | }
|
---|
44 | //! [4]
|
---|
45 |
|
---|
46 |
|
---|
47 | //! [5]
|
---|
48 | class MyClass : public QObject
|
---|
49 | {
|
---|
50 | Q_OBJECT
|
---|
51 | Q_PROPERTY(Priority priority READ priority WRITE setPriority)
|
---|
52 | Q_ENUMS(Priority)
|
---|
53 |
|
---|
54 | public:
|
---|
55 | MyClass(QObject *parent = 0);
|
---|
56 | ~MyClass();
|
---|
57 |
|
---|
58 | enum Priority { High, Low, VeryHigh, VeryLow };
|
---|
59 |
|
---|
60 | void setPriority(Priority priority);
|
---|
61 | Priority priority() const;
|
---|
62 | };
|
---|
63 | //! [5]
|
---|
64 |
|
---|
65 |
|
---|
66 | //! [6]
|
---|
67 | MyClass *myinstance = new MyClass;
|
---|
68 | QObject *object = myinstance;
|
---|
69 |
|
---|
70 | myinstance->setPriority(MyClass::VeryHigh);
|
---|
71 | object->setProperty("priority", "VeryHigh");
|
---|
72 | //! [6]
|
---|
73 |
|
---|
74 |
|
---|
75 | //! [7]
|
---|
76 | Q_CLASSINFO("Version", "3.0.0")
|
---|
77 | //! [7]
|
---|