Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QQuickView as transparent with parent window.



  • I have QQuickView window for QML, and it has QWindow as parent window, so the QQuickView is inside the parent window. I would like to get this QQuickView window as transparent, but when I set it to transparent as child window for QWindow, it is black. But if it is as own window, it is totally transparent as should.

    There is code example:

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

        QWindow window;
        window.resize(800, 640);
        window.show();
        
        QQuickView view;
        view.setSource(QUrl::fromLocalFile("qml/main.qml"));
        
        QSurfaceFormat surfaceFormat;
        surfaceFormat.setAlphaBufferSize(8);
        view.setFormat(surfaceFormat);
        
        view.setClearBeforeRendering(true);
        view.setColor(QColor(Qt::transparent));
        view.setParent(&window);
        view.show();
        
        return app.exec();
    

    }@

    And main.qml:

    @import QtQuick 2.0

    Rectangle {

    width: 300
    height: 300
    color: "#00000000" 
    Text {
        id: label
        color: "red"
        text: "TEST"
        y: 240
        x: 160
    }
    

    }@

    I use Linux desktop with Qt 5.0.1 and Qt Quick2. It doesn't matter if the parent window is also a QQuickView instead of QWindow.



  • I am not sure I understand your question. Have you also tried:

    @window.setColor(QColor(Qt::transparent));
    @

    ?

    Peter



  • I found a nice example here:
    http://stackoverflow.com/questions/14009549/how-to-make-a-transparent-window-with-qt-quick-2-0
    It's working with qt5+opengl on win7.



  • Peter:
    For QWindow there is not setColor function available. The question is that how can I get that child window transparent.

    belab:
    I've seen that already, it uses QWidget. And I would like to go without widgets, because they are just an extra layer, which I don't need. But I'll check it more deeper if it is still usable some way. Or I will use that if there is not another solution.



  • Any luck Jjompu? I found your post because I've been trying to do pretty much the same thing. I prefer a QWindow rather than QGLWidget.



  • Everything works fine if I comment out this line

    @//view.setParent(&window);@

    ... but you end up with two separate windows.

    Also, this solution doesn't seem to work at all on Android The QQuickView instance doesn't seem to show up at all. Works fine on Linux (minus the missing transparency). I'm using Qt 5.2.1 on Ubuntu 14.04



  • I'm sorry mchiasson, but I found another way to do my thing, without need of transparency.

    I wish you luck to get it work!


Log in to reply