Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QQuickView as transparent with parent window.

QQuickView as transparent with parent window.

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 4 Posters 8.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jjompu
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      donjuedo
      wrote on last edited by
      #2

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

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

      ?

      Peter

      1 Reply Last reply
      0
      • B Offline
        B Offline
        belab
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jjompu
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mchiasson
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mchiasson
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • J Offline
                J Offline
                Jjompu
                wrote on last edited by
                #7

                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!

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved