现有全屏模式后出现黑屏

我正在尝试做这样的事情:

  1. 我有一个带有单个按钮的主窗口。
  2. 按下此按钮后,所有屏幕上都会出现两个半透明窗口。它们处于全屏模式。
  3. 4秒钟后屏幕消失。

一切都很好。但是当我点击其中一个屏幕时,在消失的过程中,它变成了完全黑色。我该如何解决?

// 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()
            }
        }
    }
}

// SplashScreen.qml

import QtQuick 2.10
import QtQuick.Controls 2.2

ApplicationWindow {
    id: splash

    flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.WA_TranslucentBackground
    color: "transparent"

    Timer {
        running: true
        interval: 4000
        onTriggered: hideSplash()
    }

    function showSplash() {
        appearAnimation.start()
    }

    function hideSplash() {
        disappearAnumation.start()
    }

    background: Rectangle {
        id: bg
        color: "black"
        opacity: 0.8
    }

    SequentialAnimation {
        id: appearAnimation

        Propertyaction { target: splash; property: "visibility"; value: ApplicationWindow.FullScreen }
        NumberAnimation { target: bg; property: "opacity"; duration: 1000; to: 0.8 }
    }

    SequentialAnimation {
        id: disappearAnumation

        NumberAnimation { target: bg; property: "opacity"; duration: 2000; to: 0 }
        Propertyaction { target: splash; property: "visibility"; value: ApplicationWindow.Hidden }
    }
}

zhonglin0701 回答:现有全屏模式后出现黑屏

Denis Popov的答案是正确的,但是在这种模式下,我的应用程序有点落后。如果将模式设置为:

不会出现问题。
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
,

在程序的进一步开发过程中,我遇到了一些重画问题。例如,更改主窗体的大小将导致黑色窗体。我发现的解决方案是使用OpenGL进行渲染。您可以通过插入以下代码来做到这一点:

QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);
本文链接:https://www.f2er.com/3165761.html

大家都在问