Important: Please read the Qt Code of Conduct -

QOpenGLWidget - Rotation and Zoom in and Out

  • Hello guys!
    I managed to create a cube in 3D with the widget, but now I need to do their rotation and zoom. I've read the examples hellogl2 and cube, but did not help me much. Like that with the right and left mouse buttons to rotate power projection and scroll to zoom in and out.
    The examples I have seen on the internet are with glut, but the qt is supported so I do not use this library.
    Can anyone give me a hand?

    For example, i already try do this, but not change.
    QMatrix4x4 camera;
    void GLWidget::mousePressEvent(QMouseEvent *event)
    if(event->button() == Qt::RightButton)
    qDebug() <<"HERE!";
    camera.translate(0, 0, -1);


  • @Lays147 How much do you know about vectors, matrices and basic linear algebra type things? In my day, everyone learned computer graphics geometry, homogeneous coordinates etc from a book called Foley & van Damme; but it's probably a bit out of date now and been replaced by something else as the standard undergrad graphics text. If your program has a vertex shader, and you can pass a transform matrix to it, and the shader multiplies vertex coordinates by the matrix... then you can just multiply the transforms you want together and pass them as a single transform.

    The earlier bits of is pretty good QMatrix4x4-friendly intro, even if the OpenGL (and the Qt) is old-school (although it does use shaders, and VBOs later on).

  • Hi,
    for the rotation, you should look at this example :
    and for the knowledge of modern Opengl(>=3.3) you should read and you can read!Getting-started/Hello-Triangle to understand VAO and VBO...

Log in to reply