QGLWidget Class Reference


The QGLWidget class is a widget for rendering OpenGL graphics. More...

#include <qgl.h>

Inherits QWidget.

List of all member functions.

Public Members

Public Slots

Protected Members


Detailed Description

The QGLWidget class is a widget for rendering OpenGL graphics.

It is easy to render OpenGL graphics in Qt applications. You can create a subclass of QGLWidget and reimplement two functions: resizeGL() and paintGL(). resizeGL() is called whenever the widget has been resized. paintGL() is called when the widget needs to be updated.

    class DrawGL : public QGLWidget
    {
    public:
        DrawGL( QWidget *parent, const char *name )
            : QGLWidget(parent,name) {}

    protected:
        void paintGL()
        {
          // draw the scene
        }

        void resizeGL( int w, int h )
        {
          // setup viewport, display lists etc.
        }
    };

If you need to repaint from other places than paintGL() (a typical example is when using timers to animate scenes) you must call makeCurrent() before you draw and probably swapBuffers() when you are finished.

Like QGLContext, QGLWidget has advanced functions for requesting a new contex format and you can even set a new context.


Member Function Documentation

QGLWidget::QGLWidget ( QWidget *parent=0, const char *name=0)

Constructs an OpenGL widget with a parent widget and a name.

The default format is used.

See also: QGLFormat::defaultFormat().

QGLWidget::QGLWidget ( const QGLFormat &format, QWidget *parent=0, const char *name=0)

Constructs an OpenGL widget with a parent widget and a name.

The format argument specifies the rendering capabilities. The widget becomes invalid if the driver/hardware cannot satisfy the requested format.

See also: isValid().

const QGLContext * QGLWidget::context () const

Returns the current context.

See also: setContext().

const QGLFormat & QGLWidget::format () const

Returns the widget's format.

See also: setFormat().

void QGLWidget::paintEvent ( QPaintEvent *) [protected]

Handles paint events. Calls the virtual function paintGL().

void QGLWidget::paintGL () [virtual protected]

This virtual function is called whenever the widget needs to be painted. Reimplement it in a subclass.

void QGLWidget::resizeEvent ( QResizeEvent *) [protected]

Handles resize events. Calls the virtual function resizeGL().

void QGLWidget::resizeGL ( int width , int height) [virtual protected]

This virtual function is called whenever the widget has been resized. Reimplement it in a subclass.

void QGLWidget::setContext ( QGLContext *context)

Sets a new context for this widget. The old context is deleted.

See also: context() and setFormat().

void QGLWidget::setFormat ( const QGLFormat &format)

Sets a new format for this widget. The widget becomes invalid if the requested format cannot be satisfied.

See also: format(), setContext() and isValid().

void QGLWidget::updateGL () [slot]

Updates the widget by calling paintGL().


This file is part of the Qt toolkit, copyright © 1992-97 Troll Tech, all rights reserved.

It was generated from the following files:


Generated at 17:31, 1997/04/07 for Qt version 1.2 by the webmaster at Troll Tech