📄 qglwidget.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/src/opengl/qgl.cpp:1047 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>QGLWidget Class</title><style type="text/css"><!--h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }a:link { color: #004faf; text-decoration: none }a:visited { color: #672967; text-decoration: none }body { background: #ffffff; color: black; }--></style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr bgcolor="#E5E5E5"><td valign=center> <a href="index.html"><font color="#004faf">Home</font></a> | <a href="classes.html"><font color="#004faf">All Classes</font></a> | <a href="mainclasses.html"><font color="#004faf">Main Classes</font></a> | <a href="annotated.html"><font color="#004faf">Annotated</font></a> | <a href="groups.html"><font color="#004faf">Grouped Classes</font></a> | <a href="functions.html"><font color="#004faf">Functions</font></a></td><td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QGLWidget Class Reference<br><small>[<a href="opengl.html">OpenGL module</a>]</small></h1><p>The QGLWidget class is a widget for rendering OpenGL graphics.<a href="#details">More...</a><p><tt>#include <<a href="qgl-h.html">qgl.h</a>></tt><p>Inherits <a href="qwidget.html">QWidget</a> and <a href="qgl.html">QGL</a>.<p><a href="qglwidget-members.html">List of all member functions.</a><h2>Public Members</h2><ul><li><div class=fn><a href="#QGLWidget"><b>QGLWidget</b></a> ( QWidget * parent = 0, const char * name = 0, const QGLWidget * shareWidget = 0, WFlags f = 0 )</div></li><li><div class=fn><a href="#QGLWidget-2"><b>QGLWidget</b></a> ( const QGLFormat & format, QWidget * parent = 0, const char * name = 0, const QGLWidget * shareWidget = 0, WFlags f = 0 )</div></li><li><div class=fn><a href="#~QGLWidget"><b>~QGLWidget</b></a> ()</div></li><li><div class=fn>void <a href="#qglColor"><b>qglColor</b></a> ( const QColor & c ) const</div></li><li><div class=fn>void <a href="#qglClearColor"><b>qglClearColor</b></a> ( const QColor & c ) const</div></li><li><div class=fn>bool <a href="#isValid"><b>isValid</b></a> () const</div></li><li><div class=fn>bool <a href="#isSharing"><b>isSharing</b></a> () const</div></li><li><div class=fn>virtual void <a href="#makeCurrent"><b>makeCurrent</b></a> ()</div></li><li><div class=fn>bool <a href="#doubleBuffer"><b>doubleBuffer</b></a> () const</div></li><li><div class=fn>virtual void <a href="#swapBuffers"><b>swapBuffers</b></a> ()</div></li><li><div class=fn>QGLFormat <a href="#format"><b>format</b></a> () const</div></li><li><div class=fn>const QGLContext * <a href="#context"><b>context</b></a> () const</div></li><li><div class=fn>virtual QPixmap <a href="#renderPixmap"><b>renderPixmap</b></a> ( int w = 0, int h = 0, bool useContext = FALSE )</div></li><li><div class=fn>virtual QImage <a href="#grabFrameBuffer"><b>grabFrameBuffer</b></a> ( bool withAlpha = FALSE )</div></li><li><div class=fn>virtual void <a href="#makeOverlayCurrent"><b>makeOverlayCurrent</b></a> ()</div></li><li><div class=fn>const QGLContext * <a href="#overlayContext"><b>overlayContext</b></a> () const</div></li><li><div class=fn>const QGLColormap & <a href="#colormap"><b>colormap</b></a> () const</div></li><li><div class=fn>void <a href="#setColormap"><b>setColormap</b></a> ( const QGLColormap & cmap )</div></li></ul><h2>Public Slots</h2><ul><li><div class=fn>virtual void <a href="#updateGL"><b>updateGL</b></a> ()</div></li><li><div class=fn>virtual void <a href="#updateOverlayGL"><b>updateOverlayGL</b></a> ()</div></li></ul><h2>Static Public Members</h2><ul><li><div class=fn>QImage <a href="#convertToGLFormat"><b>convertToGLFormat</b></a> ( const QImage & img )</div></li></ul><h2>Protected Members</h2><ul><li><div class=fn>virtual void <a href="#initializeGL"><b>initializeGL</b></a> ()</div></li><li><div class=fn>virtual void <a href="#resizeGL"><b>resizeGL</b></a> ( int width, int height )</div></li><li><div class=fn>virtual void <a href="#paintGL"><b>paintGL</b></a> ()</div></li><li><div class=fn>virtual void <a href="#initializeOverlayGL"><b>initializeOverlayGL</b></a> ()</div></li><li><div class=fn>virtual void <a href="#resizeOverlayGL"><b>resizeOverlayGL</b></a> ( int width, int height )</div></li><li><div class=fn>virtual void <a href="#paintOverlayGL"><b>paintOverlayGL</b></a> ()</div></li><li><div class=fn>void <a href="#setAutoBufferSwap"><b>setAutoBufferSwap</b></a> ( bool on )</div></li><li><div class=fn>bool <a href="#autoBufferSwap"><b>autoBufferSwap</b></a> () const</div></li><li><div class=fn>virtual void <a href="#paintEvent"><b>paintEvent</b></a> ( QPaintEvent * )</div></li><li><div class=fn>virtual void <a href="#resizeEvent"><b>resizeEvent</b></a> ( QResizeEvent * )</div></li><li><div class=fn>virtual void <a href="#glInit"><b>glInit</b></a> ()</div></li><li><div class=fn>virtual void <a href="#glDraw"><b>glDraw</b></a> ()</div></li></ul><hr><a name="details"></a><h2>Detailed Description</h2>The QGLWidget class is a widget for rendering OpenGL graphics.<p> <p> QGLWidget provides functionality for displaying OpenGL<sup>*</sup> graphicsintegrated into a Qt application. It is very simple to use. Youinherit from it and use the subclass like any other <a href="qwidget.html">QWidget</a>, exceptthat instead of drawing the widget's contents using <a href="qpainter.html">QPainter</a> etc.you use the standard OpenGL rendering commands.<p> QGLWidget provides three convenient virtual functions that you canreimplement in your subclass to perform the typical OpenGL tasks:<p> <ul><li> <a href="#paintGL">paintGL</a>() - Renders the OpenGL scene. Gets called whenever the widgetneeds to be updated.<li> <a href="#resizeGL">resizeGL</a>() - Sets up the OpenGL viewport, projection, etc. Getscalled whenever the the widget has been resized (and also when itshown for the first time because all newly created widgets get aresize event automatically).<li> <a href="#initializeGL">initializeGL</a>() - Sets up the OpenGL rendering context, defines displaylists, etc. Gets called once before the first time resizeGL() orpaintGL() is called.</ul><p> Here is a rough outline of how your QGLWidget subclass may look:<p> <pre> class MyGLDrawer : public QGLWidget { Q_OBJECT // must include this if you use Qt signals/slots public: MyGLDrawer( <a href="qwidget.html">QWidget</a> *parent, const char *name ) : QGLWidget(parent,name) {} protected: void initializeGL() { // Set up the rendering context, define display lists etc.: ... glClearColor( 0.0, 0.0, 0.0, 0.0 ); glEnable(GL_DEPTH_TEST); ... } void resizeGL( int w, int h ) { // setup viewport, projection etc.: glViewport( 0, 0, (GLint)w, (GLint)h ); ... glFrustum( ... ); ... } void paintGL() { // draw the scene: ... glRotatef( ... ); glMaterialfv( ... ); glBegin( GL_QUADS ); glVertex3f( ... ); glVertex3f( ... ); ... glEnd(); ... } }; </pre> <p> If you need to trigger a repaint from places other than <a href="#paintGL">paintGL</a>() (atypical example is when using <a href="qtimer.html">timers</a> to animatescenes), you should call the widget's <a href="#updateGL">updateGL</a>() function.<p> Your widget's OpenGL rendering context is made current when paintGL(),<a href="#resizeGL">resizeGL</a>(), or <a href="#initializeGL">initializeGL</a>() is called. If you need to call thestandard OpenGL API functions from other places (e.g. in yourwidget's constructor or in your own paint functions), you must call<a href="#makeCurrent">makeCurrent</a>() first.<p> QGLWidget provides advanced functions for requesting a new display<a href="qglformat.html">format</a> and you can even set a new rendering<a href="qglcontext.html">context</a>.<p> You can achieve sharing of OpenGL display lists between QGLWidgets(see the documentation of the QGLWidget constructors for details).<p> <h3> Overlays</h3><a name="1"></a><p> The QGLWidget creates a GL overlay contextin addition to the normal context if overlays are supported by theunderlying system.<p> If you want to use overlays, you specify it in the <a href="qglformat.html">format</a>. (Note: Overlay must be requested in the formatpassed to the QGLWidget constructor.) Your GL widget should alsoimplement some or all of these virtual methods:<p> <ul><li> <a href="#paintOverlayGL">paintOverlayGL</a>()<li> <a href="#resizeOverlayGL">resizeOverlayGL</a>()<li> <a href="#initializeOverlayGL">initializeOverlayGL</a>()</ul><p> These methods work in the same way as the normal <a href="#paintGL">paintGL</a>() etc.functions, except that they will be called when the overlaycontext is made current. You can explicitly make the overlay contextcurrent by using <a href="#makeOverlayCurrent">makeOverlayCurrent</a>(), and you can access theoverlay context directly (e.g. to ask for its transparent color) bycalling <a href="#overlayContext">overlayContext</a>().<p> On X servers in which the default visual is in an overlay plane,non-GL Qt windows can also be used for overlays. See theexamples/opengl/overlay_x11 example program for details.<p> <sup>*</sup> OpenGL is a trademark of Silicon Graphics, Inc. in theUnited States and other countries.<p>See also <a href="graphics.html">Graphics Classes</a> and <a href="images.html">Image Processing Classes</a>.<hr><h2>Member Function Documentation</h2><h3 class=fn><a name="QGLWidget"></a>QGLWidget::QGLWidget ( <a href="qwidget.html">QWidget</a> * parent = 0, const char * name = 0, const <a href="qglwidget.html">QGLWidget</a> * shareWidget = 0, WFlags f = 0 )</h3>Constructs an OpenGL widget with a <em>parent</em> widget and a <em>name</em>.<p> The <a href="qglformat.html#defaultFormat">default format</a> isused. The widget will be <a href="#isValid">invalid</a> if thesystem has no <a href="qglformat.html#hasOpenGL">OpenGL support</a>.<p> The <em>parent</em>, <em>name</em> and <a href="qt.html#WidgetFlags">widget flag</a>, <em>f</em>, arguments are passed tothe <a href="qwidget.html">QWidget</a> constructor.<p> If the <em>shareWidget</em> parameter points to a valid QGLWidget, thiswidget will share OpenGL display lists with <em>shareWidget</em>. Ifthis widget and <em>shareWidget</em> have different <a href="#format">formats</a>, display list sharing may fail. You can checkwhether display list sharing succeeded by calling <a href="#isSharing">isSharing</a>().<p> The initialization of OpenGL rendering state, etc. should be done byoverriding the <a href="#initializeGL">initializeGL</a>() function, rather than in the constructorof your QGLWidget subclass.<p> <p>See also <a href="qglformat.html#defaultFormat">QGLFormat::defaultFormat</a>().<h3 class=fn><a name="QGLWidget-2"></a>QGLWidget::QGLWidget ( const <a href="qglformat.html">QGLFormat</a> & format, <a href="qwidget.html">QWidget</a> * parent = 0, const char * name = 0, const <a href="qglwidget.html">QGLWidget</a> * shareWidget = 0, WFlags f = 0 )</h3>Constructs an OpenGL widget with parent <em>parent</em>, called <em>name</em>.<p> The <em>format</em> argument specifies the desired <a href="qglformat.html">rendering options</a>. If the underlying OpenGL/Window systemcannot satisfy all the features requested in <em>format</em>, the nearestsubset of features will be used. After creation, the <a href="#format">format</a>() methodwill return the actual format obtained.<p> The widget will be <a href="#isValid">invalid</a> if thesystem has no <a href="qglformat.html#hasOpenGL">OpenGL support</a>.<p> The <em>parent</em>, <em>name</em> and <a href="qt.html#WidgetFlags">widget flag</a>, <em>f</em>, arguments are passed tothe <a href="qwidget.html">QWidget</a> constructor.<p> If the <em>shareWidget</em> parameter points to a valid QGLWidget, thiswidget will share OpenGL display lists with <em>shareWidget</em>. Ifthis widget and <em>shareWidget</em> have different <a href="#format">formats</a>, display list sharing may fail. You can checkwhether display list sharing succeeded by calling <a href="#isSharing">isSharing</a>().<p> The initialization of OpenGL rendering state, etc. should be done byoverriding the <a href="#initializeGL">initializeGL</a>() function, rather than in the constructorof your QGLWidget subclass.<p> <p>See also <a href="qglformat.html#defaultFormat">QGLFormat::defaultFormat</a>() and <a href="#isValid">isValid</a>().<h3 class=fn><a name="~QGLWidget"></a>QGLWidget::~QGLWidget ()</h3>Destroys the widget.<h3 class=fn>bool <a name="autoBufferSwap"></a>QGLWidget::autoBufferSwap () const<tt> [protected]</tt></h3><p> Returns TRUE if the widget is doing automatic GL buffer swapping;otherwise returns FALSE.<p> <p>See also <a href="#setAutoBufferSwap">setAutoBufferSwap</a>().<h3 class=fn>const <a href="qglcolormap.html">QGLColormap</a> & <a name="colormap"></a>QGLWidget::colormap () const</h3><p> Returns the colormap for this widget.<p> Usually it is only top-level widgets that can have differentcolormaps installed. Asking for the colormap of a child widget willreturn the colormap for the child's top-level widget.<p> If no colormap has been set for this widget, the QColormap returnedwill be empty.<p> <p>See also <a href="#setColormap">setColormap</a>().<h3 class=fn>const <a href="qglcontext.html">QGLContext</a> * <a name="context"></a>QGLWidget::context () const</h3>Returns the context of this widget.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -