本文整理汇总了Python中PyQt4.QtDeclarative.QDeclarativeView.rootContext方法的典型用法代码示例。如果您正苦于以下问题:Python QDeclarativeView.rootContext方法的具体用法?Python QDeclarativeView.rootContext怎么用?Python QDeclarativeView.rootContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtDeclarative.QDeclarativeView
的用法示例。
在下文中一共展示了QDeclarativeView.rootContext方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QApplication
# 需要导入模块: from PyQt4.QtDeclarative import QDeclarativeView [as 别名]
# 或者: from PyQt4.QtDeclarative.QDeclarativeView import rootContext [as 别名]
from PyQt4.QtCore import QUrl
from PyQt4.QtGui import QPushButton, QApplication
from PyQt4.QtDeclarative import QDeclarativeView
# This example uses a QML file to show a scrolling list containing
# all the items listed into dataList.
dataList = ["Item 1", "Item 2", "Item 3", "Item 4"]
app = QApplication([])
view = QDeclarativeView()
ctxt = view.rootContext()
ctxt.setContextProperty("myModel", dataList)
url = QUrl('view.qml') # <-- Problem seems to be here, the file gets copied correctly to Resources folder
view.setSource(url)
view.show()
app.exec_()
示例2: unicode
# 需要导入模块: from PyQt4.QtDeclarative import QDeclarativeView [as 别名]
# 或者: from PyQt4.QtDeclarative.QDeclarativeView import rootContext [as 别名]
return unicode(cat.name, "utf8", "ignore")
elif role == "_iconname":
# funny, but it appears like Qt does not have something
# to lookup the icon path in QIcon
icons = Gtk.IconTheme.get_default()
info = icons.lookup_icon(cat.iconname, 48, 0)
if info:
return info.get_filename()
return ""
if __name__ == "__main__":
from PyQt4.QtGui import QApplication
from PyQt4.QtDeclarative import QDeclarativeView
import sys
app = QApplication(sys.argv)
app.cache = get_pkg_info()
app.cache.open()
view = QDeclarativeView()
categoriesmodel = CategoriesModel()
rc = view.rootContext()
rc.setContextProperty('categoriesmodel', categoriesmodel)
# load the main QML file into the view
qmlpath = os.path.join(os.path.dirname(__file__), "CategoriesView.qml")
view.setSource(qmlpath)
# show it
view.show()
sys.exit(app.exec_())