View Full Version : Resize QGLWidget

3rd December 2011, 14:07
I have a program composed of a QMainWindow with a QGLWidget as its central widget. When I resize the main window, QGLWidget::resizeGL() is triggered (however, I currently have it do absolutely nothing). This is also visually displayed by the "background" of the MainWindow remaining as the QGLWidget's background color. As well, moving the mouse in the "new" parts of the widget triggers QGLWidget::mouseMoveEvent().

However, the drawing isn't rescaled. Indeed, the image remains in its original scale and position, regardless of the resize event. As well, the "drawable" area of the QGLWidget isn't altered either. If I increase the main window and then translate an image (whether the image was opened before or after the resizing) to the "new" areas of the widget, it gets clipped at the original limits of the widget. I'm not even sure what code snippets to present because I don't know what could be causing this. As I've said, my ::resizeGL() is completely empty. If I change it to basically

QGLWidget::resizeGL(int w, int h)
nothing changes.

Does QGLWidget have some "drawable" section I'm unaware of that doesn't get automatically resized?

I've attached an image showing the problem, in case I didn't explain it well enough. The original size was the same as that clipping area, while the expanded area isn't drawable.

3rd December 2011, 14:19
Why don't you use layouts?

3rd December 2011, 14:24
How would that help with my problem? As I've said, the problem isn't in resizing the QGLWidget. I've got plenty of indications that's already happening. The problem is in getting the "drawable" area of the QGLWidget to be resized with it, something I doubt layouts would help with.

3rd December 2011, 15:19
Sorry, misread you question. You should actually not resize widget itself, but rerender its content according new widget size. Good sample Hello GL Example.

3rd December 2011, 16:33
Thanks. Yeah, I had to make a call to glViewport() to redefine the GL context. That solved it, thanks.