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


Python QQmlComponent.setData方法代码示例

本文整理汇总了Python中PyQt5.QtQml.QQmlComponent.setData方法的典型用法代码示例。如果您正苦于以下问题:Python QQmlComponent.setData方法的具体用法?Python QQmlComponent.setData怎么用?Python QQmlComponent.setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtQml.QQmlComponent的用法示例。


在下文中一共展示了QQmlComponent.setData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: QCoreApplication

# 需要导入模块: from PyQt5.QtQml import QQmlComponent [as 别名]
# 或者: from PyQt5.QtQml.QQmlComponent import setData [as 别名]
app = QCoreApplication(sys.argv)

qmlRegisterType(BirthdayPartyAttached)
qmlRegisterType(BirthdayParty, "People", 1, 0, "BirthdayParty",
        attachedProperties=BirthdayPartyAttached)
qmlRegisterType(HappyBirthdaySong, "People", 1, 0, "HappyBirthdaySong")
qmlRegisterType(ShoeDescription)
qmlRegisterType(Person)
qmlRegisterType(Boy, "People", 1, 0, "Boy")
qmlRegisterType(Girl, "People", 1, 0, "Girl")

engine = QQmlEngine()

component = QQmlComponent(engine)
component.setData(QML, QUrl())

party = component.create()

if party is not None and party.host is not None:
    print("\"%s\" is having a birthday!" % party.host.name)

    if isinstance(party.host, Boy):
        print("He is inviting:")
    else:
        print("She is inviting:")

    for guest in party.guests:
        attached = qmlAttachedPropertiesObject(BirthdayParty, guest, False)

        if attached is not None:
开发者ID:death-finger,项目名称:Scripts,代码行数:32,代码来源:binding.py

示例2: ros_qml_main

# 需要导入模块: from PyQt5.QtQml import QQmlComponent [as 别名]
# 或者: from PyQt5.QtQml.QQmlComponent import setData [as 别名]
def ros_qml_main():
    try:
        rospy.init_node('ros_qml', sys.argv)
        my_argv = rospy.myargv(sys.argv)
        
        signal.signal(signal.SIGINT, sigint_handler)

        app = QApplication(my_argv)

        engine = QQmlEngine()
        engine.quit.connect(app.quit)

        plugins_dir = QLibraryInfo.location(QLibraryInfo.PluginsPath)

        # ## Add QML extension modules and plugins to the path, including ourselves
        plugins_paths = rospack.get_manifest(THIS_PACKAGE).get_export(THIS_PACKAGE, 'plugins')
        for idx, p in enumerate(plugins_paths):
            # If a relative path provided, treat it as relative to Qt plugins dir
            if not os.path.isabs(p):
                plugins_paths[idx] = plugins_dir + '/' + p

        qml_paths = rospack.get_manifest(THIS_PACKAGE).get_export(THIS_PACKAGE, 'imports')
        deps = rospack.get_depends_on(THIS_PACKAGE)
        for d in deps:
            pp = rospack.get_manifest(d).get_export(THIS_PACKAGE, 'plugins')
            for idx, p in enumerate(pp):
                # If a relative path provided, treat it as relative to Qt plugins dir
                if not os.path.isabs(p):
                    pp[idx] = plugins_dir + '/' + p

            plugins_paths += pp

            qp = rospack.get_manifest(d).get_export(THIS_PACKAGE, 'imports')
            qml_paths += qp

        for p in plugins_paths:
            engine.addPluginPath(p)

        for p in qml_paths:
            engine.addImportPath(p)

        qml_sys_path = QLibraryInfo.location(QLibraryInfo.ImportsPath)
        engine.addImportPath(qml_sys_path)

        # Somehow we need to set the path both with QQmlEngine and with environment,
        # commenting any of the two will lead to 'module not installed' error
        os.environ['QML2_IMPORT_PATH'] = ':'.join(qml_paths) + ':' + qml_sys_path

        comp = QQmlComponent(engine)
        
        if len(my_argv) > 1 and my_argv[1]:
            qml_url = my_argv[1]
            comp.loadUrl(QUrl(qml_url))
        elif rospy.has_param('qml_url'):
            qml_url = rospy.get_param('qml_url')
            comp.loadUrl(QUrl(qml_url))
        elif rospy.has_param('qml_description'):  # experimental
            qml_description = rospy.get_param('qml_description')
            # FIXME that hangs for unknown reason
            comp.setData(QByteArray(qml_description), QUrl())
        else:
            rospy.logfatal('Neither /qml_url nor /qml_description (experimental) parameter is present')
            sys.exit(1)
        
        if not comp.isReady():
            sys.stderr.write(comp.errorString())
            sys.exit(1)
        
        win = comp.create()
        if not win:
            rospy.logfatal('Your root item has to be a Window')
            sys.exit(1)
        
        engine.setIncubationController(win.incubationController())
        if win:
            win.show()
        
        # Poll Python interpreter every 500ms
        timer = QTimer()
        timer.start(500)
        timer.timeout.connect(lambda: None)

        sys.exit(app.exec_())

    except KeyboardInterrupt:
        pass
    except rospy.ROSInterruptException:
        pass
开发者ID:bgromov,项目名称:ros_qml,代码行数:90,代码来源:__init__.py


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