PDA

View Full Version : How to create transparent widgets on top of GLWidget



Anwar Said
7th September 2016, 14:39
Hi everyone,
I am quite new to OpenGL programming, and i have a problem while creating transparent widgets over glWidget. I am using Qt 4.2 with C++ on centOs(linux) operating system. The requirements of my project are: to create a glwidget on the screen with some drawing(circles, shapes and so on). then we need to create some transparent widgets over the openGL widget in such a way that the drawing over glWidget should be visible under the new child widgets.
The main files i have created is:
First i have a main Widget (Form), and a child openGLWidget on the top of the main widget. Now the problem is that when i am creating transparent child widgets over the glWidget, then the system desktop is visible under the child widget instead of the drawing over glWidget. Some part of my code is:



//constructor of MainWindow:
// object of GLWidget
glWidget = new GLWidget();
glWidget ->setParent(this);
glWidget ->resize(1024,800);
glWidget ->show();

//creating object for child widget
childWidget = new Form(glWidget );
childWidget ->setParent(glWidget);
childWidget ->setGeometery(1024-320,300,300,300);
childWidget ->show();


//constructor of child widget which should be transparent over the above glWidget
widget.setupUi(this);
setWindowFlags(Qt::FrameLessWindowHint);
setAutoFillBackground(false);
setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_TransparentForMouseEvents);
setAttribute(Qt::WA_ContentsPropagated);

Any help will be appreciated.

Thanks.

wysota
9th September 2016, 10:02
"Circles, shapes and so on" are not good candidates for widgets. Instead you can implement your GL code in paintGL() and paint your shapes in paintEvent() of a QGLWidget.