Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QML Window opacity doesn't work when fullscreen

Tags:

qt

qt-quick

qml

I've experienced a strange problem: when a QML Window is fullscreen, its opacity property doesn't work, so the window stay opaque. When the window isn't fullscreen (e.g. maximized), it works properly.

Do you have any ideas how to deal with this problem? In fact, I want to animate fullscreen window fading in.

The code:

main.qml

import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Window 2.1

Window {
    visible: true
    visibility: "FullScreen"

    opacity: 0.5

    Text {
        id: text
        text: "Hello World"
        font.pointSize: 36
        color: "#333"
    }
}

main.cpp

#include <QApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:///main.qml")));

    return app.exec();
}

I use Qt 5.3 on Windows 8.1.

like image 438
Ivan Akulov Avatar asked Oct 19 '25 03:10

Ivan Akulov


1 Answers

This is the age-old bug of the Qt/Win combination - windows with an OpenGL context, can't be made transparent without employing trickery. The solution is to embed your QML application in a QQuickWidget and make that transparent and full-screen. There also exists another workaround (using the 'DWM' API, which is nonportable - you can read about it in the bug description).

https://bugreports.qt.io/browse/QTBUG-28214

like image 81
user1095108 Avatar answered Oct 21 '25 17:10

user1095108



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!