PDA

View Full Version : Background color of GLWidget



mullwaden
21st August 2008, 15:44
Is it possible to set the background color of a glWidget? If I use a command such as glClearColor(...) then the whole widget takes that color even though the actual viewport of the openGL might not be covering the whole widget.

wysota
21st August 2008, 17:08
What do you mean it might not be covering the whole widget?

mullwaden
21st August 2008, 17:51
Well with a code like this for example:

double side = std::min(width / ratio, height);
glViewport(int(width - side*ratio) / 2, int(height - side) / 2, int(side*ratio), int(side));

where width and height is the widgets extents, I would get an image thats always a certain ratio 4:3 or 16:9 for example.

wysota
21st August 2008, 18:24
Ok, but the rest is still occupied by the gl context, so you have to use OpenGL means to change the background color. I think glClear() should clear everything, not only the GL viewport. If I'm mistaken and you are talking about something else, then try using QPalette and changing the background role colour.