【问题标题】:Black screen after existing FullScreen mode现有全屏模式后黑屏
【发布时间】:2020-10-12 15:48:00
【问题描述】:

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

  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 }
    }
}

【问题讨论】:

    标签: c++ qt qml


    【解决方案1】:

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

    QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);
    

    【讨论】:

    • 这真的拯救了我的一天。在我的情况下,Qt::AA_UseOpenGLES 效果更好,它似乎不那么滞后。
    【解决方案2】:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-07
      相关资源
      最近更新 更多