How to overlay a QWidget such as QLabel overy a Qt 5.0 QWindow with the transparent part works like QWidget overly QWidget?
-
When I use a QLabel overly a QWindow by
@
#include "paintedwindow.h"
#include "ScadeWidget.h"#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <QLabel>ScadeWidget::ScadeWidget(QWidget *parent):QWidget(parent)
{
scadeWindow = new PaintedWindow;// Combining Qt Widgets and QML with QWidget::createWindowContainer() // http://www.ics.com/blog/combining-qt-widgets-and-qml-qwidgetcreatewindowcontainer#.UlzdRlAge-U // OpenGL in Qt 5.1 – Part 5 // http://www.kdab.com/opengl-in-qt-5-1-part-5/ // OpenGL Window Example // http://qt-project.org/doc/qt-5.1/qtgui/openglwindow.html container = QWidget::createWindowContainer(scadeWindow, this); container->setMinimumSize(scadeWindow->width(), scadeWindow->height());
#if 1
//We can directly use Qt UI file to overlap OpenGL.
auto label = new QLabel("Hello, the world!", this);
label->move(100,50);
label->setAttribute(Qt::WA_TranslucentBackground);
label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
#endif
}
@
The showed label comes with non-transparent staff. Ineed, the paintedwindow comes from the qt
examples C:\Qt\Qt5.1.1\5.1.1\msvc2010_opengl\examples\opengl\paintedwindowas the following picture shows, the hello world's background should be blue :
!http://s15.postimg.org/acxqqtc55/QQ_20131209162947.jpg(The in transparent draw.)!