Qt OpenGL project[SOLVED]

  • Hello!

    I decided to try an OpenGL technique in Qt. But from the first base step I have a small problem. What kind of project I need to create? Is it a common Qt Widget Project or is it GLSL?

    Thank you for answers beforehand.

  • Yes, it is a common qt widget project. For doing this you have to create your own QGLWidget class, which heritates QGLWidget and declare the 3 virtual functions:

    1. void initializeGL();
    2. void paintGL();
    3. void resizeGL(int , int );

    I am working an Qt OpenGL project right now. Here you have a class example from my program:
    @class QOpenGL : public QGLWidget {

    void initializeGL();
    void paintGL();
    void resizeGL(int , int );
    void mousePressEvent(QMouseEvent*);
    void mouseReleaseEvent(QMouseEvent*);
    void mouseMoveEvent(QMouseEvent*);

    explicit QOpenGL(QWidget *parent = 0);
    ~QOpenGL() { doneCurrent(); }
    You can see in fact that the QGLWidget is a child class of QWidget. On my example I re-implemented the mouse functions (from QWidget) in order to have control on mouse input. You can see Qt Help for more info.


  • I forgot, in your project file .pro you should also add the following line:
    @QT += opengl@

  • Thank you for your answer!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.