问题描述
如何防止我的 QML 窗口在所有 QML 内容可用之前显示?
在我下面的示例中,在创建 QQmlApplicationEngine
后会显示一个空窗口,但在调用 app.exec_()
之前不会出现 QML 内容。我的示例代码中的 time.sleep(1)
夸大了效果。窗口是白色的,一秒钟后它显示红色背景。
我需要做什么才能在窗口出现时显示所有 QML 内容?或者更确切地说,如何在所有 QML 内容准备就绪之前阻止显示窗口?
我在 Windows 上运行。
QML
import QtQuick
import QtQuick.Controls
ApplicationWindow {
color: "red"
visible: true
}
代码
import time
from PySide6 import QtQml,QtWidgets
app = QtWidgets.QApplication([])
engine = QtQml.QQmlApplicationEngine("app_window.qml")
# This sleep exaggerates the issue so that you can easily observe
# that an empty window is shown by this point without QML content.
# Without the sleep the empty window looks like a white "flash"
# before the QML content is shown. I want to get rid of this "flash",# so I don't want the empty window to ever be visible!
time.sleep(1)
app.exec_()
这是我所看到的慢动作记录,以 1/8 速度播放,没有 time.sleep()
。注意窗口最初显示时是白色的,然后变成红色(好吧,我的手机变成了橙色)。我希望窗口从可见的第一刻起就变成红色。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)