QQuickWindow transparent

im using QQmlApplicationEngine with QQuickWindow for the application, and I cannot transparent main window. I want to set a splash before the application appears, and I use the Window component for it, and it should be transparent, but it’s not, my main.cpp

int main(int argc, char *argv[]) { Application app(argc, argv); QShookaClient shooka_client; QQmlApplicationEngine engine; engine.rootContext()->setContextProperty("shooka", &shooka_client); engine.load(QUrl("qrc:///shooka/shooka.qml")); QObject *topLevel = engine.rootObjects().value(0); QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel); window->show(); window->setFlags(Qt::FramelessWindowHint); window->setColor(Qt::transparent); return app.exec(); } 

but setColor does not work in win7. I know there is a way for QDeclarativeView, or even I found a solution for QQuickview, and it seems to work for QQuickWindow, but no, can someone help me.

+6
source share
3 answers

You need to understand that the QtQuick Window type maps to the QQuickWindow C ++ class and derives from QWindow . Window flags for each Cameron response can be set. But you also need to set the opacity , say, 0.75 to make it translucent. All this can be done in QML, no need to set flags from C ++.

screenshot

 import QtQuick 2.1 import QtQuick.Controls 1.0 import QtQuick.Window 2.0 ApplicationWindow { title: qsTr("Hello World") width: 640 height: 480 flags: Qt.SubWindow | Qt.Tool | Qt.FramelessWindowHint | Qt.WindowSystemMenuHint | Qt.WindowStaysOnTopHint opacity: 0.75 visible: true menuBar: MenuBar { Menu { title: qsTr("File") MenuItem { text: qsTr("Exit") onTriggered: Qt.quit(); } } } Button { text: "Hello World" anchors.centerIn: parent } } 
+4
source

I know this is an old question, but since it is not marked as resolved, here is my approach:

 import QtQuick 2.4 import QtQuick.Controls 1.3 ApplicationWindow { title: qsTr("Hello World") width: 640 height: 480 flags: Qt.FramelessWindowHint color: "transparent" visible: true Rectangle { color:"red" width: parent.width/2 height: parent.height/2;anchors.centerIn: parent } } 

As a result, you get a transparent background with a red rectangle in the middle. You can easily change this rectangle for the image.

Hope helped someone.

+4
source

You can use the following code to achieve a frameless transparent window effect:

 setWindowFlags( #ifdef Q_OS_MAC Qt::SubWindow | #else Qt::Tool | #endif Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowStaysOnTopHint ); setAttribute(Qt::WA_NoSystemBackground, true); // set the parent widget background to translucent setAttribute(Qt::WA_TranslucentBackground, true); setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); // create a display widget for displaying child widgets QWidget* displayWidget = new QWidget; displayWidget->setStyleSheet(".QWidget { background-color: rgba(0, 0, 0, 75%); border-width: 1px; border-style: solid; border-radius: 10px; border-color: #555555; } .QWidget:hover { background-color: rgba(68, 68, 68, 75%); border-width: 2px; border-style: solid; border-radius: 10px; border-color: #ffffff; }"); 

The idea is that your parent window or the containing window does not have a frame and has a translucent background. Then you set the child QWidget inside the parent QWidget and apply the styles using QSS for transparency.

0
source

Source: https://habr.com/ru/post/952835/


All Articles