Semi-transparent widget on QOpenGLWidget has incorrect color brightness
-
Here simple test code:
//*.h #ifndef FORM_H #define FORM_H #include <QOpenGLWidget> #include <QOpenGLFunctions_3_0> class Form : public QOpenGLWidget, protected QOpenGLFunctions_3_0 { Q_OBJECT public: explicit Form(QWidget *parent = 0); // QOpenGLWidget interface protected: void initializeGL() Q_DECL_OVERRIDE; }; #endif // FORM_H
// *.cpp #include "form.h" #include <QPushButton> Form::Form(QWidget *parent) : QOpenGLWidget(parent) { QPushButton *f = new QPushButton("f", this); QPushButton *s = new QPushButton("s", this); s->move(20,10); f->setStyleSheet("background-color: white;"); s->setStyleSheet("background-color: rgba(255,0,0,160);"); } void Form::initializeGL() { initializeOpenGLFunctions(); glClearColor(1,1,1,1); }
Result is:
The color of whole button should be like in marked circle. How to solve this problem.
[Edit: Added code tags -- @Wieland]
-
Here simple test code:
//*.h #ifndef FORM_H #define FORM_H #include <QOpenGLWidget> #include <QOpenGLFunctions_3_0> class Form : public QOpenGLWidget, protected QOpenGLFunctions_3_0 { Q_OBJECT public: explicit Form(QWidget *parent = 0); // QOpenGLWidget interface protected: void initializeGL() Q_DECL_OVERRIDE; }; #endif // FORM_H
// *.cpp #include "form.h" #include <QPushButton> Form::Form(QWidget *parent) : QOpenGLWidget(parent) { QPushButton *f = new QPushButton("f", this); QPushButton *s = new QPushButton("s", this); s->move(20,10); f->setStyleSheet("background-color: white;"); s->setStyleSheet("background-color: rgba(255,0,0,160);"); } void Form::initializeGL() { initializeOpenGLFunctions(); glClearColor(1,1,1,1); }
Result is:
The color of whole button should be like in marked circle. How to solve this problem.
[Edit: Added code tags -- @Wieland]
-
Here simple test code:
//*.h #ifndef FORM_H #define FORM_H #include <QOpenGLWidget> #include <QOpenGLFunctions_3_0> class Form : public QOpenGLWidget, protected QOpenGLFunctions_3_0 { Q_OBJECT public: explicit Form(QWidget *parent = 0); // QOpenGLWidget interface protected: void initializeGL() Q_DECL_OVERRIDE; }; #endif // FORM_H
// *.cpp #include "form.h" #include <QPushButton> Form::Form(QWidget *parent) : QOpenGLWidget(parent) { QPushButton *f = new QPushButton("f", this); QPushButton *s = new QPushButton("s", this); s->move(20,10); f->setStyleSheet("background-color: white;"); s->setStyleSheet("background-color: rgba(255,0,0,160);"); } void Form::initializeGL() { initializeOpenGLFunctions(); glClearColor(1,1,1,1); }
Result is:
The color of whole button should be like in marked circle. How to solve this problem.
[Edit: Added code tags -- @Wieland]
Button 2 has an alpha value of 160, Button 1 ist pure (255,255,255,255) where they overlap the background blends with the other button. Exactly as intended.
if you want the blended color as the default color for button 2 then change your CSS
IIRC Blend works like this?
res.r = dst.r * (1 - src.a) + src.r * src.a res.g = dst.g * (1 -src.a) + src.g * src.a res.b = dst.b * (1 - src.a) + src.b * src.a
so your target rgba should be (255,95,95,255).
-
The main problem is that 1 button has non-opaque white background and GL background has non-opaque white color, but button 2 has different color on them. In fact, overlaping 1 button is working properly, so why overlaping GL context gives not correct results?
-
Button 2 has an alpha value of 160, Button 1 ist pure (255,255,255,255) where they overlap the background blends with the other button. Exactly as intended.
if you want the blended color as the default color for button 2 then change your CSS
IIRC Blend works like this?
res.r = dst.r * (1 - src.a) + src.r * src.a res.g = dst.g * (1 -src.a) + src.g * src.a res.b = dst.b * (1 - src.a) + src.b * src.a
so your target rgba should be (255,95,95,255).
@J.Hilk Thanks for reply. But i need semi-transparent widget on opengl context and problem is that semi-transparent widgets overlap opengl with wrong color(it is darker than should be), in the sample higher i just show that widget-widget overlaping works properly, but widget-glwidget not. More than that if you draw in paintGL rect with rgba(1,0,0,0.62) 0.62 = 160 / 255 and turn on blend with blending SRC_ALPHA, ONE_MINUS_SRC_ALPHA you will see proper color. Try yourself and I will be grateful if you told me how to fix this.
-
@Devopia53 Hi! thanks for replay! I have tested on 5.7.0/mingw/msvc on two machines(one has integrated card, second has video card nvidia), but on both incorrect results, I am so sad. Is yours 'main.cpp' looks like this:
#include <QApplication> #include "form.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); Form f; f.show(); return a.exec(); }
-
@Devopia53 Hi! thanks for replay! I have tested on 5.7.0/mingw/msvc on two machines(one has integrated card, second has video card nvidia), but on both incorrect results, I am so sad. Is yours 'main.cpp' looks like this:
#include <QApplication> #include "form.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); Form f; f.show(); return a.exec(); }
-
@Devopia53
Result incorrect. :-( Can you print your QSurfaceFormat(qDebug() << form.context().format()) to compare with mine
my debug is:QSurfaceFormat(version 4.3, options QFlags(0x4), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 8, stencilBufferSize 8, samples 0, swapBehavior 2, swapInterval 1, profile 2)
-
@Devopia53
Result incorrect. :-( Can you print your QSurfaceFormat(qDebug() << form.context().format()) to compare with mine
my debug is:QSurfaceFormat(version 4.3, options QFlags(0x4), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 8, stencilBufferSize 8, samples 0, swapBehavior 2, swapInterval 1, profile 2)
QSurfaceFormat(version 3.3, options QFlags(0x4), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 8, stencilBufferSize 8, samples 0, swapBehavior 2, swapInterval 1, profile 2)
-
QSurfaceFormat(version 3.3, options QFlags(0x4), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 8, stencilBufferSize 8, samples 0, swapBehavior 2, swapInterval 1, profile 2)
@Devopia53 I tested on Qt 5.8/Win7 today. The same incorrect result. But today i discovered the difference in overlaping behavior on my two machines. On the machine with video card fully-transparent widget has black color on white opengl context :D, where as other machine with integrated video card has no color(as should). So the gui transparency on opengl context is very platform dependent. Solution is to render widget by opengl directly but this way is very inconvenient. I think troll-tech must solve this problem in future.