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(). The resizeGL() method is called whenever the widget has been resized (and also when it shown for the first time, since all newly created widgets get a resize event automatically). paintGL() is called when the widget needs to be updated.

    class MyGLDrawer : public QGLWidget
    {
        Q_OBJECT        // include this if you use Qt signals/slots

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

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

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

If you need to repaint from other places than paintGL() (a typical example is when using timers to animate scenes), you can call the updateGL() function.

When paintGL() or resizeGL() is called, your widget has been made current. If you need to call the standard OpenGL API functions from other places (e.g. in your widget's constructor), you must call makeCurrent() first.

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


Member Function Documentation

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

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

The default format is used.

The parent, name and f arguments are passed to the QWidget constructor.

Note: If the constructor of your QGLWidget subclass calls any OpenGL functions, it must first call makeCurrent() to set the correct rendering context.

See also: QGLFormat::defaultFormat().

QGLWidget::QGLWidget ( const QGLFormat & format, QWidget * parent=0, const char * name=0, WFlags f=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.

The parent, name and f arguments are passed to the QWidget constructor.

Note: If the constructor of your QGLWidget subclass calls any OpenGL functions, it must first call makeCurrent() to set the correct rendering context.

See also: QGLFormat::defaultFormat() and isValid().

QGLWidget::~QGLWidget ()

Destroys the widget.

const QGLContext * QGLWidget::context () const

Returns the current context.

See also: setContext().

bool QGLWidget::doubleBuffer () const

Returns TRUE if double buffering is set in the format for this widget.

See also: QGLFormat::doubleBuffer().

const QGLFormat & QGLWidget::format () const

Returns the widget's format.

See also: setFormat().

bool QGLWidget::isValid () const

Returns TRUE if the widget was able to satisfy the specified constraints.

void QGLWidget::makeCurrent ()

Makes this widget the current widget for OpenGL operations. I.e. makes this widget's rendering context the current OpenGL rendering context.

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.

There is no need to call makeCurrent() because this has already been done when the function is called.

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.

There is no need to call makeCurrent() because this has already been done when the function is called.

void QGLWidget::setContext ( QGLContext * context )

Sets a new context for this widget. The context must be created using new. QGLWidget will delete the context when another context is set or when the widget is destroyed.

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::swapBuffers ()

Swaps the screen contents with an off-screen buffer. Works only if the widget's format specifies double buffer mode.

See also: doubleBuffer() and QGLFormat::setDoubleBuffer().

void QGLWidget::updateGL () [slot]

Updates the widget by calling paintGL().


This file is part of the OpenGL support for the Qt toolkit, copyright © 1992-97 Troll Tech, all rights reserved. You may use the OpenGL support classes on the same terms that you may use Qt.

It was generated from the following files:


Generated at 23:51, 1998/03/16 for Qt OpenGL extension version 1.0 by the webmaster at Troll Tech