/tmp/snapshot-pyside-6.2-rel/pyside-setup/examples/uitools/uiloader¶
(You can also check this code in the repository)
"""QUiLoader example, showing how to dynamically load a Qt Designer form
from a UI file."""
from argparse import ArgumentParser, RawTextHelpFormatter
import sys
from PySide6.QtCore import Qt, QFile, QIODevice
from PySide6.QtWidgets import QApplication, QWidget
from PySide6.QtUiTools import QUiLoader
if __name__ == '__main__':
arg_parser = ArgumentParser(description="QUiLoader example",
formatter_class=RawTextHelpFormatter)
arg_parser.add_argument('file', type=str, help='UI file')
args = arg_parser.parse_args()
ui_file_name = args.file
app = QApplication(sys.argv)
ui_file = QFile(ui_file_name)
if not ui_file.open(QIODevice.ReadOnly):
reason = ui_file.errorString()
print(f"Cannot open {ui_file_name}: {reason}")
sys.exit(-1)
loader = QUiLoader()
widget = loader.load(ui_file, None)
ui_file.close()
if not widget:
print(loader.errorString())
sys.exit(-1)
widget.show()
sys.exit(app.exec())
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.