Qt5 -> Qt6 - partial window transparency
-
Hi all,
I'm trying to port an application from Qt5 to Qt6, but I'm having some trouble getting (partial) window transparency to work in Windows (it works just fine in Linux).
To test this, I simply created a new project in QtCreator for Qt5 (5.15) and Qt6 (6.2), so it's a simple Window with a "Hello World" title. I then add
color: #88000000to bothWindowelements, build it and run it. The Qt5 version looks as expected, the window is black and partially transparent. The Qt6 version, however, does not have any transparency at all.If I do the same, however, on Linux, then both look exactly the same.
Did anybody run into this before, or does anybody have an idea what to look into?
Thanks!
-
Hi all,
I'm trying to port an application from Qt5 to Qt6, but I'm having some trouble getting (partial) window transparency to work in Windows (it works just fine in Linux).
To test this, I simply created a new project in QtCreator for Qt5 (5.15) and Qt6 (6.2), so it's a simple Window with a "Hello World" title. I then add
color: #88000000to bothWindowelements, build it and run it. The Qt5 version looks as expected, the window is black and partially transparent. The Qt6 version, however, does not have any transparency at all.If I do the same, however, on Linux, then both look exactly the same.
Did anybody run into this before, or does anybody have an idea what to look into?
Thanks!
@aran
How do you create a Window?When using QQuickView, I can make it work with the following code:
// See https://stackoverflow.com/questions/14009549/how-to-make-a-transparent-window-with-qt-quick-2-0 QSurfaceFormat surfaceFormat; surfaceFormat.setAlphaBufferSize(8); pQuickView->setFormat(surfaceFormat); pQuickView->setColor(QColor(Qt::transparent));(a semi-transparent color should work then, as well)
-
Thank you for your reply!
I've been using
QQmlApplicationEngineto load and display the window. If I switch it toQQuickViewI also don't get a transparent window.Here is the example code I'm running:
main.cpp:
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQuickView> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); // creating application using engine // when uncommenting this also make sure to replace // Rectangle by Window in Main.qml /* QQmlApplicationEngine engine; const QUrl url(u"qrc:/transparenttest/Main.qml"_qs); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url);*/ // creating the application using view QQuickView *view = new QQuickView; view->setSource(QUrl("qrc:/transparenttest/Main.qml")); QSurfaceFormat surfaceFormat; surfaceFormat.setAlphaBufferSize(8); view->setFormat(surfaceFormat); view->setColor(QColor(qRgba(0,0,0,128))); view->show(); return app.exec(); }(the commented out code is the default code provided by qt creator and (afaict) the recommended way (?) of creating qml applications.)
Main.qml:
import QtQuick import QtQuick.Controls import QtQuick.Window // use Window when running it with QQmlApplicationEngine //Window { Rectangle { width: 640 height: 480 visible: true color: "#88000000" }It also has some strange behavior when resizing the window, in particular when making it larger. The newly added areas are indeed semi-transparent. It seems like there is a central item or rectangle in the background that is all white at startup and stays around but doesn't resize...
-
Thank you for your reply!
I've been using
QQmlApplicationEngineto load and display the window. If I switch it toQQuickViewI also don't get a transparent window.Here is the example code I'm running:
main.cpp:
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQuickView> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); // creating application using engine // when uncommenting this also make sure to replace // Rectangle by Window in Main.qml /* QQmlApplicationEngine engine; const QUrl url(u"qrc:/transparenttest/Main.qml"_qs); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url);*/ // creating the application using view QQuickView *view = new QQuickView; view->setSource(QUrl("qrc:/transparenttest/Main.qml")); QSurfaceFormat surfaceFormat; surfaceFormat.setAlphaBufferSize(8); view->setFormat(surfaceFormat); view->setColor(QColor(qRgba(0,0,0,128))); view->show(); return app.exec(); }(the commented out code is the default code provided by qt creator and (afaict) the recommended way (?) of creating qml applications.)
Main.qml:
import QtQuick import QtQuick.Controls import QtQuick.Window // use Window when running it with QQmlApplicationEngine //Window { Rectangle { width: 640 height: 480 visible: true color: "#88000000" }It also has some strange behavior when resizing the window, in particular when making it larger. The newly added areas are indeed semi-transparent. It seems like there is a central item or rectangle in the background that is all white at startup and stays around but doesn't resize...
@aran I would try setting view color and surface format before loading source
Also, you might want to try different RHI backends, and see how they behave.