Important: Please read the Qt Code of Conduct -

Resizing QGL Widget

  • I don't know how to properly resize my openGL viewport when the widgetsize is changed. it somehow works when i initially call myWidget->resize() - but once the widget is shown on screen, resize doesn't work anymore.

    here is my code:

    @int main (int argc, char **argv) {
    QApplication app(argc, argv);
    QGLFormat glFormat;
    glFormat.setProfile( QGLFormat::CompatibilityProfile);

    QGLWidget* render_qglwidget = new MyWidget(glFormat);

    glContext = (QGLContext *) render_qglwidget->context();
    render_qglwidget->resize(720, 486);
    return app.exec();

    And in MyWidget (that inherits from QGLWidget) i have:

    @void MyWidget::resizeGL(int w, int h){

    void MyWidget::paintGL(){

    so - what i would expect is to see a white triangle, with one corner in the middle of the window, one in the top-middle of the window and one in the right-middle of the window. when the window opens, this is exactly the case (so the glViewport function seems to work) but when i start resizing the window, the triangle stays exactly the same size (i ould expect it to scale together with the window) although glViewport is called with new values and also paintGL is called

    What am I missing?

  • This happen wen toy can't see the glWidget expanding, try to glClearColor, to
    fill the background:

    void MyWidget::resizeGL(int width, int height)
    glViewport(0, 0, (GLint)width, (GLint)height);

    void MyWidget::initializeGL()
    glClearColor(0.0, 0.0, 0.0, 0.0);

    void MyWidget::paintGL()

  • You need also to change projection matrix.

Log in to reply