[qt5] Transparent (windows 7 aero) widget
-
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?
-
setWindowOpacity an alternative would be to make transparent
-
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(QLatin1String("qml/main.qml")); viewer.setWindowFlags(Qt::FramelessWindowHint); viewer.setAttribute(Qt::WA_TranslucentBackground); viewer.setStyleSheet("background:transparent;"); viewer.setResizeMode(QDeclarativeView::SizeViewToRootObject); viewer.showExpanded(); return app->exec();
}@
But I have no clue how to port the previous code to Qt5, and keeping the transparent background?
any working solution here?
-
Any progress on this topic?
Thank you,
Regards,
Bill -
nope!!
:(I have tried different approaches.
- Using a QWidget as a top level, but I am not able to load QML content inside it.
- 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" ! -
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 -
Ooops, apparently that drawBackground method does not exist any longer apparently...
Bill -
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() << 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(QStringLiteral("qml/myProject/main.qml")); 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 -
The solution is perfect! +1 from me!
P.S. Thanks a lot! -
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 -
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@ -
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.
-
@billouparis How did you achieved transparency in windows having in mind what was said by elpuri?
-
I must have a build with openGL flag for sure! I compiled Qt libraries myself!
-
Hi @billouparis how to build the Qt Lib, without ANGLE? Thanks!
-
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);
#endifw.show(); w.move(200,100); return a.exec();
}@
-
I have find the resolution in http://qt-project.org/forums/viewthread/24344 Now I have get transparent dialog!