9
9
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
11
<title>Integrating Python and QML — PyQt 4.9.5 Reference Guide</title>
11
<title>Integrating Python and QML — PyQt 4.9.6 Reference Guide</title>
13
13
<link rel="stylesheet" href="_static/default.css" type="text/css" />
14
14
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
26
26
<script type="text/javascript" src="_static/underscore.js"></script>
27
27
<script type="text/javascript" src="_static/doctools.js"></script>
28
28
<link rel="shortcut icon" href="_static/logo_tn.ico"/>
29
<link rel="top" title="PyQt 4.9.5 Reference Guide" href="index.html" />
29
<link rel="top" title="PyQt 4.9.6 Reference Guide" href="index.html" />
30
30
<link rel="next" title="Integrating Python and JavaScript in QtWebKit" href="webkit.html" />
31
31
<link rel="prev" title="Support for QSettings" href="pyqt_qsettings.html" />
46
46
<li class="right" >
47
47
<a href="pyqt_qsettings.html" title="Support for QSettings"
48
48
accesskey="P">previous</a> |</li>
49
<li><a href="index.html">PyQt 4.9.5 Reference Guide</a> »</li>
49
<li><a href="index.html">PyQt 4.9.6 Reference Guide</a> »</li>
60
60
<p>Qt v4.7 introduced QML as a means of declaratively describing a user interface
61
61
and using JavaScript as a scripting language within QML. It is possible to
62
62
write complete standalone QML applications, or to combine them with C++.</p>
63
<p>PyQt supports the integration of Python and QML as far as it can - given the
63
<p>PyQt4 supports the integration of Python and QML as far as it can - given the
64
64
limitations of the QML implementation.</p>
65
65
<p>There are three types of QML application:</p>
66
66
<ul class="simple">
67
67
<li><em>Pure</em> applications that are written entirely in QML and can be run using the
68
<strong class="program">qmlviewer</strong> tool provided with Qt. PyQt fully supports this type of
69
application. The examples provided by <strong class="program">qtdemo.py</strong> under the <em>Qt
68
<strong class="program">qmlviewer</strong> tool provided with Qt. PyQt4 fully supports this type
69
of application. The examples provided by <strong class="program">qtdemo.py</strong> under the <em>Qt
70
70
Declarative Examples</em> heading are all of this type.</li>
71
71
<li>QML allows <tt class="docutils literal"><span class="pre">QObject</span></tt> instances to be used in QML applications. QML code is
72
72
able to call an object’s slots and has read and write access to the object’s
73
73
properties. QML code can also respond to changes to the value of a property.
74
PyQt fully supports the use objects created in Python in this way. The
74
PyQt4 fully supports the use objects created in Python in this way. The
75
75
<strong class="program">minehunt.py</strong> example under the <em>Demonstrations</em> heading of
76
76
<strong class="program">qtdemo.py</strong> is an example of this type of application.</li>
77
77
<li>QML also allows <tt class="docutils literal"><span class="pre">QObject</span></tt> sub-classes to be used in QML applications so
78
that new instances are created from QML. PyQt does not support this. The
78
that new instances are created from QML. PyQt4 does not support this. The
79
79
reason is that QML uses information generated at compile time (specifically
80
80
it uses <tt class="docutils literal"><span class="pre">QObject::staticMetaObject</span></tt>) rather than information created
81
81
dynamically at run time (i.e. <tt class="docutils literal"><span class="pre">QObject::metaObject()</span></tt>). This approach is
84
84
place any restriction on the functionality of a Python/QML application, it
85
85
only places restrictions on how that application is written.</li>
87
<p>QML can implement JavaScript functions and define signals. PyQt allows both of
88
these to be accessed transparently from Python. The following is a simple
87
<p>QML can implement JavaScript functions and define signals. PyQt4 allows both
88
of these to be accessed transparently from Python. The following is a simple
89
89
example application that displays the current date and time when the user
91
91
<p>The following is the QML (in the <tt class="file docutils literal"><span class="pre">message.qml</span></tt>) that defines the user