C++ 现有全屏模式后出现黑屏
我想做这样一件事:C++ 现有全屏模式后出现黑屏,c++,qt,qml,C++,Qt,Qml,我想做这样一件事: 我有一个只有一个按钮的主窗口 按下此按钮后,所有屏幕上都会出现两个半透明窗口。它们处于全屏模式 4秒后屏幕消失 一切都好。但当我点击其中一个屏幕时,在消失的过程中,它变成了一片漆黑。我怎样才能修好它 // main.qml import QtQuick 2.10 import QtQuick.Window 2.10 import QtQuick.Controls 2.2 Window { id: main visible: true width:
// main.qml
import QtQuick 2.10
import QtQuick.Window 2.10
import QtQuick.Controls 2.2
Window {
id: main
visible: true
width: 100
height: 50
title: "Hello Splash World"
Button {
anchors.fill: parent
text: "Show splash"
onClicked: {
for (var i = 0; i < Qt.application.screens.length; ++i) {
var component = Qt.createComponent("SplashScreen.qml");
var window = component.createObject(main, {screen: Qt.application.screens[i]});
window.height = Qt.application.screens[i].height
window.width = Qt.application.screens[i].width
window.showSplash()
}
}
}
}
在我的程序的进一步开发过程中,我遇到了一些关于重新绘制的奇怪问题。例如,更改主窗体的大小会导致将黑色窗体更改为。我找到的解决方案是使用OpenGL进行渲染。您可以通过插入以下代码来执行此操作:
QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);
丹尼斯·波波夫的回答是正确的,但在这种模式下,我的应用程序有点滞后。如果模式设置为:
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
另一方面,每次创建窗口时,我都会在输出中收到以下警告:
DXGI WARNING: IDXGIFactory::CreateSwapChain: Blt-model swap effects (DXGI_SWAP_EFFECT_DISCARD and DXGI_SWAP_EFFECT_SEQUENTIAL) are legacy swap effects that are predominantly superceded by their flip-model counterparts (DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL and DXGI_SWAP_EFFECT_FLIP_DISCARD). Please consider updating your application to leverage flip-model swap effects to benefit from modern presentation enhancements. More information is available at http://aka.ms/dxgiflipmodel. [ MISCELLANEOUS WARNING #294: ]
到目前为止,我提出的最佳解决方案是使用一个标志在调试模式下运行应用程序,使用另一个标志在发布/部署模式下运行应用程序:
#ifdef QT_DEBUG
QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);
#else
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
#endif
那真的救了我一天。在我的例子中,Qt::AA_UseOpenGLES工作得更好,它看起来不那么滞后。
#ifdef QT_DEBUG
QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);
#else
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
#endif