【发布时间】:2016-05-28 18:33:20
【问题描述】:
QML 的有趣问题。当我创建一个默认的 Qt Quick 应用程序并运行它时,我得到一个黑屏。窗口和其他项目根本不渲染。但是当我最小化它并再次将其返回到以前的状态时,就会呈现项目。那么有人知道这种问题吗? Before minimizing After minimizing
在一个非常相似的情况下(对于另一个用户),正在创建窗口,但没有呈现任何项目。在这种情况下,窗口完全是空白(白色)而不是黑色。
该系统是带有 Qt 5.15 的 Windows 10。此问题未出现在非 Windows 系统上。
(解决方案与OpenGL有关,详见下文。)
import QtQuick 2.5
import QtQuick.Window 2.2
Window {
visible: true
width: 500
height: 500
Rectangle {
id: test
width: 300
height: 200
color: "red"
border.color: "black"
border.width: 4
}
Rectangle {
width: test.width / 2
height: test.height / 2
color: "red"
border.color: "black"
border.width: 4
anchors.centerIn: parent
Rectangle {
width: parent.width / 2
height: parent.height / 2
radius: width * 0.5
//x: 200
//y: 200
color: "green"
border.color: "darkgreen"
border.width: 4
anchors.left: parent.left
anchors.bottom: parent.bottom
}
}
}
【问题讨论】:
-
它按预期对我有用(Windows 8 / Qt 5.6)。可能是显卡或 VM/OpenGL 问题。
-
根据我使用有问题的显卡和 Qt Quick 的经验,我可以建议使用以下标志或类似标志测试应用程序:
QGuiApplication::setAttribute(Qt::AA_UseOpenGLES);。在加载 QML 之前在 C++ 中设置它。
标签: c++ qt opengl qml qtquick2