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. [Qt5] How to make a QQuickView TranslucentBackground?
Forum Updated to NodeBB v4.3 + New Features

[Qt5] How to make a QQuickView TranslucentBackground?

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 3 Posters 8.6k 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.
  • W Offline
    W Offline
    weiyuemin
    wrote on last edited by
    #1

    I want to use setAttribute(Qt::WA_TranslucentBackground), it used to be a method of QDeclarativeView in Qt4.8.3.

    When I replace QDeclarativeView with QQuickView, the setAttribute method disappears..

    I noticed that QQuickView is inherited from QQuickWindow, it seemed not related with QWidget, when the old QDeclarativeView is indirectly inherited from QWidget( setAttribute is a method of QWidget ).

    So in Qt5 how can I implement a TranslucentBackground window that using qml? (Meanwhile I want to use QtQuick 2.0)

    Thank you !

    1 Reply Last reply
    0
    • B Offline
      B Offline
      billouparis
      wrote on last edited by
      #2

      this code works for me under Ubuntu 12.10

      @#include <QtGui/QGuiApplication>
      #include "qtquick2applicationviewer.h"
      #include <QDebug>

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

      QtQuick2ApplicationViewer viewer;
      viewer.setSurfaceType(QSurface::OpenGLSurface);
      
      QSurfaceFormat format;
      format.setAlphaBufferSize(8);
      format.setRenderableType(QSurfaceFormat::OpenGL);
      qDebug() <&lt; format.hasAlpha();
      viewer.setFormat(format);
      
      QColor color;
      color.setRedF(0.0);
      color.setGreenF(0.0);
      color.setBlueF(0.0);
      color.setAlphaF(0.0);
      viewer.setColor(color);
      
      viewer.setClearBeforeRendering(true);
      
      //viewer.setFlags(Qt::FramelessWindowHint);
      
      viewer.setMainQmlFile&#40;QStringLiteral("qml/MaskTest/main.qml"&#41;);
      viewer.showExpanded();
      
      return app.exec();
      

      }
      @

      Hope it helps
      Bill

      1 Reply Last reply
      0
      • W Offline
        W Offline
        weiyuemin
        wrote on last edited by
        #3

        Thank you Bill,
        Follow your code, I write this:

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

        QQuickView view;

        view.setSurfaceType(QSurface::OpenGLSurface);

        QSurfaceFormat format;
        //QSurfaceFormat format = view.format();
        format.setAlphaBufferSize(8);
        format.setRenderableType(QSurfaceFormat::OpenGL);
        qDebug() <&lt; format.hasAlpha();
        view.setFormat(format);
        
        QColor color;
        color.setRedF(0.0);
        color.setGreenF(0.0);
        color.setBlueF(0.0);
        color.setAlphaF(0.0);
        view.setColor(color);
        
        view.setClearBeforeRendering(true);
        
        view.connect(view.engine(), SIGNAL(quit()), SLOT(close()));  
        view.setFlags(Qt::FramelessWindowHint);
        
        view.setSource(QUrl::fromLocalFile&#40;"qml/test.qml"&#41;);
        

        view.show();

        return app->exec();
        }
        @

        the program will crash when executing app->exec(), it said:

        ASSERT: "context" in file opengl\qopenglfunctions.cpp, line 194

        then I pressed alt+esc, it poped another error:

        ASSERT failure in QSGNode::appendChildNode: "QSGNode already has a parent", file scenegraph\coreapi\qsgnode.cpp, line 404

        Comment view.setFormat(format); would make the program running without crash, but it's not transparent. The area should be transparent now is in black color.

        I'm using WinXP.

        The remaining problem is why I can't call setFormat method. Is there anyone facing the same problem?

        1 Reply Last reply
        0
        • W Offline
          W Offline
          weiyuemin
          wrote on last edited by
          #4

          According to this issue, https://bugreports.qt-project.org/browse/QTBUG-28214
          Transparent OpenGL windows are currently not supported on Windows?

          1 Reply Last reply
          0
          • B Offline
            B Offline
            billouparis
            wrote on last edited by
            #5

            You might find the beginning of a solution in this topic:
            http://qt-project.org/forums/viewthread/18984/

            In windows XP, the issues might be related to:
            -windows XP window manager itself (as in Windows 7)
            -the way you compiled your qt5, don't forget to use option -opengl if you want to use your video hardware.

            Regards,
            Bill

            1 Reply Last reply
            0
            • W Offline
              W Offline
              weiyuemin
              wrote on last edited by
              #6

              Thank you Bill, I will try to compile Qt5 with opengl and report my results here.

              1 Reply Last reply
              0
              • W Offline
                W Offline
                weiyuemin
                wrote on last edited by
                #7

                I compiled with -opengl desktop. Now using your code, the program will not crash, but still not transparent. The area should be transparent has a black background.

                So it is because transparent OpenGL windows are not supported on Windows?

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  diorahman
                  wrote on last edited by
                  #8

                  Interesting, what we have now?

                  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