Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QQuickWindow transparent

Tags:

qt

im using QQmlApplicationEngine with QQuickWindow for an application and i can't transparent main window. i want to set a splash before application pops up and i use Window component for it and it should be transparent but it's not, my main.cpp is

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 doesn't work in win7. i know there is way for QDeclarativeView or even i found solution for QQuickview and it kinda should work for QQuickWindow but no, can anyone help me please..

like image 242
ali Avatar asked Aug 30 '13 13:08

ali


2 Answers

One has to realize that a Window QtQuick type maps to QQuickWindow C++ class, and derives from QWindow. The window flags, per Cameron's answer, can be set. But you also need to set the opacity to, say, 0.75 to make it translucent. All of this can be done in QML, no need for setting 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
    }
}
like image 80
Kuba hasn't forgotten Monica Avatar answered Nov 15 '22 16:11

Kuba hasn't forgotten Monica


I know this is an old question, but as it is not marked as solved, 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 result, you will get a transparent background with a red rectangle in the middle. You could easily change that rectangle for an image.

Hope helped someone.

like image 25
albertTaberner Avatar answered Nov 15 '22 15:11

albertTaberner