当前位置: 首页>>代码示例>>Python>>正文


Python QDeclarativeView.rootContext方法代码示例

本文整理汇总了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_()
开发者ID:EthanSeaver,项目名称:Python-Projects,代码行数:21,代码来源:main.py

示例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_())
开发者ID:pombredanne,项目名称:shop,代码行数:32,代码来源:categoriesmodel.py


注:本文中的PyQt4.QtDeclarative.QDeclarativeView.rootContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。