本文整理汇总了Python中PyQt5.QtQml.QQmlComponent.loadUrl方法的典型用法代码示例。如果您正苦于以下问题:Python QQmlComponent.loadUrl方法的具体用法?Python QQmlComponent.loadUrl怎么用?Python QQmlComponent.loadUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtQml.QQmlComponent
的用法示例。
在下文中一共展示了QQmlComponent.loadUrl方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_country_names_from_code
# 需要导入模块: from PyQt5.QtQml import QQmlComponent [as 别名]
# 或者: from PyQt5.QtQml.QQmlComponent import loadUrl [as 别名]
def init_country_names_from_code(locale):
'''Init the country description as found in GCompris geography/resource/board/board*.qml'''
'''in the global descriptions hash'''
po = None
try:
po = polib.pofile( gcompris_qt + '/po/gcompris_' + locale + '.po')
except:
print "**ERROR: Failed to load po file %s**" %(gcompris_qt + '/po/gcompris_' + locale + '.po')
print ''
app = QCoreApplication(sys.argv)
engine = QQmlEngine()
component = QQmlComponent(engine)
for qml in glob.glob(gcompris_qt + '/src/activities/geography/resource/board/*.qml'):
component.loadUrl(QUrl(qml))
board = component.create()
levels = board.property('levels')
for level in levels.toVariant():
if level.has_key('soundFile') and level.has_key('toolTipText'):
sound = level['soundFile'].split('/')[-1].replace('$CA', 'ogg')
tooltip = level['toolTipText']
if po:
tooltip = po.find(tooltip).msgstr if po.find(tooltip) else tooltip
descriptions[sound] = tooltip
示例2: get_geography_on_letter_from_code
# 需要导入模块: from PyQt5.QtQml import QQmlComponent [as 别名]
# 或者: from PyQt5.QtQml.QQmlComponent import loadUrl [as 别名]
def get_geography_on_letter_from_code():
'''Return all the countries in geography/resource/board/board-x.json'''
words = set()
app = QCoreApplication(sys.argv)
engine = QQmlEngine()
component = QQmlComponent(engine)
for qml in glob.glob(gcompris_qt + '/src/activities/geography/resource/board/*.qml'):
component.loadUrl(QUrl(qml))
board = component.create()
levels = board.property('levels')
for level in levels.toVariant():
if level.has_key('soundFile') and (not level.has_key('type') or level['type'] != "SHAPE_BACKGROUND"):
sound = level['soundFile'].split('/')[-1].replace('$CA', 'ogg')
words.add(sound)
return words
示例3: main
# 需要导入模块: from PyQt5.QtQml import QQmlComponent [as 别名]
# 或者: from PyQt5.QtQml.QQmlComponent import loadUrl [as 别名]
def main():
# Set up correct Ctrl-C behavior.
signal.signal(signal.SIGINT, signal.SIG_DFL)
app = QGuiApplication( sys.argv )
engine = QQmlEngine()
engine.addImportPath( path.join( path.dirname( __file__ ), 'ui', 'qml' ) )
core.register_types()
component = QQmlComponent( engine )
component.loadUrl( QUrl( '/home/feoh3/.config/nube/hud.qml' ) )
if component.isError():
print( "\n".join( error.toString() for error in component.errors() ) )
else:
window = component.create()
app.exec_()
示例4: QQmlEngine
# 需要导入模块: from PyQt5.QtQml import QQmlComponent [as 别名]
# 或者: from PyQt5.QtQml.QQmlComponent import loadUrl [as 别名]
appLabel.show()
# Create a QML engine.
engine = QQmlEngine()
# Initialize PhotoBoothEngine.
pbengine = PhotoBoothEngine()
pbengine.on_status.connect(appLabel.rootObject().status)
pbengine.on_update_filter_preview.connect(appLabel.rootObject().updateImageFilterPreview)
appLabel.rootContext().setContextProperty('pbengine', pbengine)
# Create a component factory and load the QML script.
print("Hello")
component = QQmlComponent(appLabel.engine())
component.loadUrl(QUrl('TextStatusFly.qml'))
print("Hello2")
asdf = component.create(appLabel.rootContext())
print("Hello3")
asdf.setParentItem(appLabel.rootObject())
asdf.setParent(appLabel.rootObject())
print("Hello4")
#asdf.setProperty("targetX", 100)
asdf.setProperty("objectName", "textStatusBar")
print("Hello5")
appLabel.rootContext().setContextProperty('textStatusBar', asdf)
示例5: QApplication
# 需要导入模块: from PyQt5.QtQml import QQmlComponent [as 别名]
# 或者: from PyQt5.QtQml.QQmlComponent import loadUrl [as 别名]
from PyQt5.QtQml import QQmlComponent, QQmlApplicationEngine
from PyQt5.QtQuick import QQuickWindow
from view_model import ViewModel
if __name__ == '__main__':
myApp = QApplication(sys.argv)
engine = QQmlApplicationEngine()
context = engine.rootContext()
engine.addImportPath("/home/bob/Qt/5.11.2/Automotive/sources/qtapplicationmanager/dummyimports/")
# create a view model
view_model = ViewModel()
# bind the view model to the context
context.setContextProperty('view_model', view_model)
component = QQmlComponent(engine)
component.loadUrl(QUrl('mainwindow.qml'))
# some boilerplate to make sure the component is ready before showing
if component.status() != QQmlComponent.Ready:
if component.status() == QQmlComponent.Error:
sys.exit(component.errorString())
root_window: QQuickWindow = component.create()
myApp.exec_()
sys.exit()
示例6: QQmlApplicationEngine
# 需要导入模块: from PyQt5.QtQml import QQmlComponent [as 别名]
# 或者: from PyQt5.QtQml.QQmlComponent import loadUrl [as 别名]
#engine = QQmlApplicationEngine()
# doesn't quite work because we aren't actually using the component associated
# with this engine
engine.quit.connect(app.quit)
# from http://pyqt.sourceforge.net/Docs/PyQt5/qml.html
# Register the Python type. Its URI is 'People', it's v1.0 and the type
# will be called 'Person' in QML.
qmlRegisterType(Weather, 'WeatherCategory', 1, 0, 'Weather')
qmlRegisterType(DataPoint, 'WeatherCategory', 1, 0, 'DataPoint')
qmlRegisterType(DataBlock, 'WeatherCategory', 1, 0, 'DataBlock')
qmlRegisterType(Geocoder, 'WeatherCategory', 1, 0, 'Geocoder')
component = QQmlComponent(engine)
component.loadUrl(QUrl('WeatherDash.qml'))
# Create the QML user interface. Auto creates its own engine
view = QQuickView()
engine2 = view.engine
# Does not run
#engine2.quit.connect(app.quit)
#view.setSource(QUrl('PyTest.qml'))
# To Satisfy cool-retro-term needs
view.rootContext().setContextProperty('devicePixelRatio', app.devicePixelRatio())
view.setSource(QUrl('WeatherDash.qml'))
#view.setResizeMode(QDeclarativeView.SizeRootObjectToView)
view.setGeometry(100, 100, 750, 480)
示例7: QGuiApplication
# 需要导入模块: from PyQt5.QtQml import QQmlComponent [as 别名]
# 或者: from PyQt5.QtQml.QQmlComponent import loadUrl [as 别名]
# -*- coding : utf-8 -*-
from PyQt5.QtCore import QUrl,QCoreApplication
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtQml import QQmlEngine,QQmlComponent
import os
import sys
app = QGuiApplication(sys.argv)
engine = QQmlEngine()
component = QQmlComponent(engine)
component.loadUrl(QUrl("main.qml"))
top = component.create()
if top :
top.show()
sys.exit(app.exec_())
示例8: name
# 需要导入模块: from PyQt5.QtQml import QQmlComponent [as 别名]
# 或者: from PyQt5.QtQml.QQmlComponent import loadUrl [as 别名]
return self._name
@name.setter
def name(self, name):
self._name = name
@pyqtProperty(int)
def shoeSize(self):
return self._shoeSize
@shoeSize.setter
def shoeSize(self, shoeSize):
self._shoeSize = shoeSize
app = QCoreApplication(sys.argv)
qmlRegisterType(Person, 'People', 1, 0, 'Person')
engine = QQmlEngine()
component = QQmlComponent(engine)
component.loadUrl(QUrl('example.qml'))
person = component.create()
if person is not None:
print "The person's name is %s." % person.name
print "They wear a size %d shoe." % person.shoeSize
else:
for error in component.errors():
print error.toString()
示例9: QApplication
# 需要导入模块: from PyQt5.QtQml import QQmlComponent [as 别名]
# 或者: from PyQt5.QtQml.QQmlComponent import loadUrl [as 别名]
#!/usr/bin/env python3
import sys
from PyQt5.QtCore import pyqtProperty, QObject, QUrl
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQml import qmlRegisterType, QQmlComponent, QQmlEngine
# Create the application instance.
app = QApplication(sys.argv)
# Create a QML engine.
engine = QQmlEngine()
# Create a component factory and load the QML script.
component = QQmlComponent(engine)
component.loadUrl(QUrl('main.qml'))
# get window
window = component.create()
window.show()
app.exec_()
示例10: ros_qml_main
# 需要导入模块: from PyQt5.QtQml import QQmlComponent [as 别名]
# 或者: from PyQt5.QtQml.QQmlComponent import loadUrl [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
示例11: shoeSize
# 需要导入模块: from PyQt5.QtQml import QQmlComponent [as 别名]
# 或者: from PyQt5.QtQml.QQmlComponent import loadUrl [as 别名]
self._name = name
@shoeSize.setter
def shoeSize(self, shoeSize):
self._shoeSize = shoeSize
app = QCoreApplication(sys.argv)
loop = QEventLoop(app)
asyncio.set_event_loop(loop)
qmlRegisterType(Person, 'People', 1, 0, 'Person')
engine = QQmlEngine()
component = QQmlComponent(engine)
component.loadUrl(QUrl('person.qml'))
person = component.create()
if person is not None:
print("The person's name is {}".format(person.name))
print("They wear a size {} shoe".format(person.shoeSize))
else:
for error in component.errors():
print(error.toString())
loop.run_forever()