Hi Robert, 2010/12/3 Robert Garrett <[email protected]>: > We're developing a QML/Python application using PySide. We need to > update the display from within python so we've done the following: > > QML snippet: > > Item { > Text { > id: myText > opacity: my_test_opacity > text: "Hello World" > } > } > > Python: > # Hide text > rootContext.setContextProperty( "my_test_opacity", 1 ) > > The problem with this method is that when we run the application there > are large number of reference errors from the qml files - in the > example code here, the qml file doesn't have any knowledge of > my_test_opacity until we explicitly set it in the python. > > This doesn't seem to cause any problems in the user interface - it all > works as we expect it to - but it's a little disconcerting to see all > the errors! > > It also indicates that perhaps we're using the wrong technique here - > can anyone recommend a better/different way of updating the interface > from python that doesn't invoke ReferenceErrors? Is there a best > practise recommendation?
First, make sure that you are using a recent version of PySide. The recently released 1.0.0 beta 1 should be fine, you can also use the buildscripts (from http://gitorious.org/pyside/buildscripts) to build directly from Git and install it into $HOME. A good way to update stuff is to subclass QObject and give it some properties (that are ideally notifyable), and set this QObject as context property. A good example is this tutorial (ignore the threading part, just have a look at how the QObject is structured with the properties and the notification signals, and how these properties are accessed in QML): http://developer.qt.nokia.com/wiki/Updating_QML_content_from_Python_threads Improvement suggestions are very welcome, as I'm always looking for a better and cleaner way to do these things. If you don't want to write all that boilerplate code just for defining a QObject with some properties that emit a signal when changed, try this (which is even more hack-ish and might be an insult to a Python developer's eye, but works for me for small projects): http://developer.qt.nokia.com/wiki/Auto-generating_QObject_from_template_in_PySide HTH. Thomas _______________________________________________ PySide mailing list [email protected] http://lists.openbossa.org/listinfo/pyside
