Qt Design Studio+Pyside项目

Qt Design Studio设计出的项目结构有多个层级的目录,我们直接用类似Qt Creator工具的方式加载main.qml文件时会报错提示module "content" is not installed,将content加入importPath后还是报同样的错误。
Qt Design Studio生成的文件包含了.qml、ui.qml、json、qmldir等多种文件,除了导入给定的文件外,我们经常会导入js文件以及图片文件、字体文件等。

最终经过多番查找资料和尝试,有以下三种解决方法:
可以参考该连接:https://doc.qt.io/qt-6/qtqml-syntax-directoryimports.html#directory-listing-qmldir-files
1.使用完整的路径来引入模块,比如引入content/App.qml时,使用import "content"导入content下的App,此时要求你的qml文件的首字母大写,这样就会自动把App.qml识别为App模块。
备注:常见的导入和引用如下:

import "./content"
......
APP{}
import "./MyScript.js" as MyScript
......
MyScript.testFunction()

2.使用qmldir来声明module,qmldir的声明分为文件列表声明和模块声明。具体参见:https://doc.qt.io/qt-6/qtqml-modules-qmldir.html#module-import-declaration

需要注意的是qml文件自己会识别当前目录子目录下的qmldir文件。
最终的结果如下:
在这里插入图片描述
3.生成qrc文件并转为rc.py文件,在python中引入转换后的rc.py文件。
引用时使用qrc:引用。


若出现下面报错,说明成功解决了自定义文件引入问题,但QtQuick.Studio.相关的库没有引入。

QQmlApplicationEngine failed to load component
file:///E:/Workspace/QT/PySider6/QtDesignStudio/main.qml:3:1: Type App unavailable
file:///E:/Workspace/QT/PySider6/QtDesignStudio/content/App.qml:14:5: Type Screen01 unavailable
file:///E:/Workspace/QT/PySider6/QtDesignStudio/content/Screen01.ui.qml: Type Constants unavailable
file:///E:/Workspace/QT/PySider6/QtDesignStudio/imports/QtDesignStudio/Constants.qml:3:1: module "QtQuick.Studio.Application" is not installed

解决方法(未解决):
D:\ProgramFiles\Qt\Tools\QtDesignStudio\qt6_design_studio_reduced_version\qml\QtQuick中的Studio文件夹复制到E:\home\.conda\envs\Python310\Lib\site-packages\PySide6\qml\QtQuick

在Python中使用PySide6实现读取文件时的环形进度条,可以按照以下步骤进行操作: 1. 首先,确保已经安装了PySide6库。可以使用以下命令进行安装: ```shell pip install PySide6 ``` 2. 创建一个Python脚本,并导入必要的模块: ```python from PySide6.QtWidgets import QApplication, QMainWindow, QProgressBar from PySide6.QtCore import Qt, QThread, Signal ``` 3. 创建一个自定义的线程类,用于模拟文件读取的进度: ```python class FileReadThread(QThread): progressChanged = Signal(int) def run(self): total_size = 1000 # 假设文件总大小为1000 for i in range(total_size): self.progressChanged.emit(i) self.msleep(10) # 模拟读取文件的延迟 ``` 4. 创建一个主窗口类,并在其中添加一个环形进度条: ```python class MainWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("文件读取进度") self.resize(300, 200) self.progress_bar = QProgressBar(self) self.progress_bar.setGeometry(50, 50, 200, 200) self.progress_bar.setRange(0, 1000) # 设置进度条的范围 self.file_read_thread = FileReadThread() self.file_read_thread.progressChanged.connect(self.update_progress) self.file_read_thread.start() def update_progress(self, value): self.progress_bar.setValue(value) ``` 5. 创建一个应用程序对象,并运行主窗口: ```python app = QApplication([]) window = MainWindow() window.show() app.exec() ``` 这样,当运行该脚本时,会显示一个带有环形进度条的窗口,进度条会模拟文件读取的进度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值