Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [qt5] Transparent (windows 7 aero) widget

[qt5] Transparent (windows 7 aero) widget

Scheduled Pinned Locked Moved General and Desktop
17 Posts 8 Posters 17.4k 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.
  • Z Offline
    Z Offline
    zodiac
    wrote on last edited by
    #1

    Hello.
    How I can set transparent attribute to widget in qt5?
    For this action in Qt4 I do:
    @ hr = pDwmExtendFrameIntoClientArea((HWND)widget->winId(), &m);
    if (SUCCEEDED(hr)) {
    result = true;
    windowNotifier()->addWidget(widget);
    }

        widget->setAttribute(Qt::WA_TranslucentBackground, result);@
    

    but this doesn't work in qt5.

    Or maybe how I can make aero window the other way in qt5?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      francomartins
      wrote on last edited by
      #2

      setWindowOpacity an alternative would be to make transparent

      1 Reply Last reply
      0
      • D Offline
        D Offline
        danut.iurascu
        wrote on last edited by
        #3

        Does it work using setOpacity for you? I have tried to use it but as an effect the entire window (including all the children) gets transparent, and not only the background.

        for eg: using Qt 4.x
        it was easy, by using setAttribute(Qt::WA_TranslucentBackground); and viewer.setStyleSheet("background:transparent;");
        @
        #include <QtGui/QApplication>
        #include "qmlapplicationviewer.h"
        #include <QtDeclarative>
        #include <QDeclarativeContext>

        Q_DECL_EXPORT int main(int argc, char *argv[])
        {
        QScopedPointer<QApplication> app(createApplication(argc, argv));

        QmlApplicationViewer viewer;
        viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
        viewer.setMainQmlFile&#40;QLatin1String("qml/main.qml"&#41;);
        viewer.setWindowFlags(Qt::FramelessWindowHint);
        viewer.setAttribute(Qt::WA_TranslucentBackground);
        viewer.setStyleSheet("background:transparent;");
        viewer.setResizeMode(QDeclarativeView::SizeViewToRootObject);
        viewer.showExpanded();
         
        return app->exec&#40;&#41;;
        

        }@

        But I have no clue how to port the previous code to Qt5, and keeping the transparent background?

        any working solution here?

        regards,
        Dănuț

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

          Any progress on this topic?
          Thank you,
          Regards,
          Bill

          1 Reply Last reply
          0
          • D Offline
            D Offline
            danut.iurascu
            wrote on last edited by
            #5

            nope!!
            :(

            I have tried different approaches.

            1. Using a QWidget as a top level, but I am not able to load QML content inside it.
            2. usind setOpacity(0.0) but this does not work (makes the entire window- also all the children)
              3.using OpenGL (but I have not succeed -> using OpenGL as surface type and overwrite the paint method in QQuickView class )

            I am out of ideas.
            the only thing which gives me hope is that "I am not alone" !

            regards,
            Dănuț

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

              Overwrite the drawBackground method and try this code:
              @void QmlApplicationViewer::drawBackground(QPainter* painter, const QRectF&)
              {
              painter->beginNativePainting();
              #ifdef arm
              glClearDepthf(1.f);
              #else
              glClearDepth(1);
              #endif
              glClearColor(0.f, 0.f, 0.f, 0.0f);
              glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);

              painter->endNativePainting();
              }
              @

              Let me know if this works,
              thank you!
              Bill

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

                Ooops, apparently that drawBackground method does not exist any longer apparently...
                Bill

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

                  Ok apparently my code is OK
                  @#include <QtGui/QGuiApplication>
                  #include "qtquick2applicationviewer.h"
                  #include <QSurface>
                  #include <QSurfaceFormat>
                  #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/myProject/main.qml"&#41;);
                  viewer.showExpanded();
                  
                  
                  return app.exec();
                  

                  }
                  @

                  from my investigation on the Qt5 side in
                  void QSGDefaultRenderer::render() and then in
                  void QSGBindable::clear(QSGRenderer::ClearMode mode) const,
                  the glClear call is performed correctly, but sadly and this is my
                  conclusion, Windows is doing something under Qt that can not be directly/easily controlled from within Qt.

                  What do you think?
                  Bill

                  1 Reply Last reply
                  0
                  • I Offline
                    I Offline
                    Itehnological
                    wrote on last edited by
                    #9

                    The solution is perfect! +1 from me!
                    P.S. Thanks a lot!

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

                      Found something in the end.
                      First activate the aero feature, second use my test application (source code: http://dl.free.fr/nZHhZVRui),
                      finally you will get something that will look like this:

                      !http://i48.tinypic.com/35bcxmh.png()!

                      Enjoy,
                      Bill

                      1 Reply Last reply
                      0
                      • I Offline
                        I Offline
                        Itehnological
                        wrote on last edited by
                        #11

                        There is a problem with your solution in Windows, when setting:

                        @format.setRenderableType(QSurfaceFormat::OpenGL);@

                        Which results in the output:
                        @Cant find EGLConfig, returning null config
                        QQuickWindow: makeCurrent() failed...
                        ASSERT: "context" in file opengl\qopenglfunctions.cpp, line 194@

                        1 Reply Last reply
                        0
                        • E Offline
                          E Offline
                          elpuri
                          wrote on last edited by
                          #12

                          You get that error, because you're asking for an OpenGL surface and your Qt is configured to use ANGLE which provides an OpenGL ES2 interface using DirectX. If you change the parameter to QSurfaceFormat::OpenGLES it'll make the error go away, but I doubt it will make the transparency work as a QQuickWindow is always OpenGL anyway.

                          1 Reply Last reply
                          0
                          • I Offline
                            I Offline
                            Itehnological
                            wrote on last edited by
                            #13

                            @billouparis How did you achieved transparency in windows having in mind what was said by elpuri?

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

                              I must have a build with openGL flag for sure! I compiled Qt libraries myself!

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

                                Hi @billouparis how to build the Qt Lib, without ANGLE? Thanks!

                                1 Reply Last reply
                                0
                                • Z Offline
                                  Z Offline
                                  zhaoweiwei
                                  wrote on last edited by
                                  #16

                                  Who know why QMainWindow are completely invisible whenever TranslucentBackground is set?
                                  as fallow:
                                  @int main(int argc, char *argv[])
                                  {
                                  QApplication::setStyle("cleanlooks");
                                  QApplication a(argc, argv);
                                  login w; // class login : public QMainWindow
                                  w.setWindowTitle("ClientLogin");

                                  w.setWindowOpacity(1);
                                  w.setWindowFlags(Qt::FramelessWindowHint);
                                  

                                  #ifndef NEWQT //I define this micro for Qt5, because in qt5 WA_TranslucentBackground will cause window invisible
                                  w.setAttribute(Qt::WA_TranslucentBackground);
                                  #endif

                                  w.show();
                                  w.move(200,100);
                                  return a.exec&#40;&#41;;
                                  

                                  }@

                                  1 Reply Last reply
                                  0
                                  • Z Offline
                                    Z Offline
                                    zhaoweiwei
                                    wrote on last edited by
                                    #17

                                    I have find the resolution in http://qt-project.org/forums/viewthread/24344 Now I have get transparent dialog!

                                    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