在所有 QML 内容可用之前,如何防止显示我的 QML 窗口?
在下面的示例中,创建后显示了一个空窗口,但 QML 内容在调用QQmlApplicationEngine
之前不会出现。app.exec_()
我的示例代码中的效果被夸大了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()
. 注意窗口最初显示时是白色的,然后变成红色(好吧,我的手机把它变成了橙色)。我希望窗口从可见的第一刻起就变成红色。