Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-updates > by-pkgid > d5e62c01ae8d1e579463c6a871dd44bf > files > 2370

qtbase5-doc-5.12.6-2.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qgl.cpp -->
  <title>QGLWidget Class | Qt OpenGL</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td >Qt 5.12</td><td ><a href="qtopengl-index.html">Qt OpenGL</a></td><td ><a href="qtopengl-module.html">C++ Classes</a></td><td >QGLWidget</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtopengl-index.html">Qt 5.12.6 Reference Documentation</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#public-slots">Public Slots</a></li>
<li class="level1"><a href="#static-public-members">Static Public Members</a></li>
<li class="level1"><a href="#protected-functions">Protected Functions</a></li>
<li class="level1"><a href="#reimplemented-protected-functions">Reimplemented Protected Functions</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
<li class="level2"><a href="#overlays">Overlays</a></li>
<li class="level2"><a href="#painting-techniques">Painting Techniques</a></li>
<li class="level2"><a href="#threading">Threading</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QGLWidget Class</h1>
<!-- $$$QGLWidget-brief -->
<p>The <a href="qglwidget.html">QGLWidget</a> class is a widget for rendering OpenGL graphics. <a href="#details">More...</a></p>
<!-- @@@QGLWidget -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QGLWidget&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += opengl</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <a href="../qtwidgets/qwidget.html">QWidget</a></td></tr></table></div><p><b>This class is obsolete.</b> It is provided to keep old source code working. We strongly advise against using it in new code.</p>
<ul>
<li><a href="qglwidget-members.html">List of all members, including inherited members</a></li>
<li><a href="qglwidget-obsolete.html">Obsolete members</a></li>
</ul>
<a name="public-functions"></a>
<h2 id="public-functions">Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#QGLWidget">QGLWidget</a></b>(QWidget *<i>parent</i> = nullptr, const QGLWidget *<i>shareWidget</i> = nullptr, Qt::WindowFlags <i>f</i> = ...)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#QGLWidget-1">QGLWidget</a></b>(QGLContext *<i>context</i>, QWidget *<i>parent</i> = nullptr, const QGLWidget *<i>shareWidget</i> = nullptr, Qt::WindowFlags <i>f</i> = ...)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#QGLWidget-2">QGLWidget</a></b>(const QGLFormat &amp;<i>format</i>, QWidget *<i>parent</i> = nullptr, const QGLWidget *<i>shareWidget</i> = nullptr, Qt::WindowFlags <i>f</i> = ...)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#dtor.QGLWidget">~QGLWidget</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> GLuint </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#bindTexture">bindTexture</a></b>(const QImage &amp;<i>image</i>, GLenum <i>target</i> = GL_TEXTURE_2D, GLint <i>format</i> = GL_RGBA)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> GLuint </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#bindTexture-1">bindTexture</a></b>(const QPixmap &amp;<i>pixmap</i>, GLenum <i>target</i>, GLint <i>format</i>, QGLContext::BindOptions <i>options</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> GLuint </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#bindTexture-2">bindTexture</a></b>(const QImage &amp;<i>image</i>, GLenum <i>target</i>, GLint <i>format</i>, QGLContext::BindOptions <i>options</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> GLuint </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#bindTexture-3">bindTexture</a></b>(const QPixmap &amp;<i>pixmap</i>, GLenum <i>target</i> = GL_TEXTURE_2D, GLint <i>format</i> = GL_RGBA)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> GLuint </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#bindTexture-4">bindTexture</a></b>(const QString &amp;<i>fileName</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> const QGLColormap &amp;</td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#colormap">colormap</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QGLContext *</td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#context">context</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#deleteTexture">deleteTexture</a></b>(GLuint <i>id</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#doneCurrent">doneCurrent</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#doubleBuffer">doubleBuffer</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#drawTexture">drawTexture</a></b>(const QRectF &amp;<i>target</i>, GLuint <i>textureId</i>, GLenum <i>textureTarget</i> = GL_TEXTURE_2D)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#drawTexture-1">drawTexture</a></b>(const QPointF &amp;<i>point</i>, GLuint <i>textureId</i>, GLenum <i>textureTarget</i> = GL_TEXTURE_2D)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QGLFormat </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#format">format</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QImage </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#grabFrameBuffer">grabFrameBuffer</a></b>(bool <i>withAlpha</i> = false)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#isSharing">isSharing</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#isValid">isValid</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#makeCurrent">makeCurrent</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#makeOverlayCurrent">makeOverlayCurrent</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> const QGLContext *</td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#overlayContext">overlayContext</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#qglClearColor">qglClearColor</a></b>(const QColor &amp;<i>c</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#qglColor">qglColor</a></b>(const QColor &amp;<i>c</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QPixmap </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#renderPixmap">renderPixmap</a></b>(int <i>w</i> = 0, int <i>h</i> = 0, bool <i>useContext</i> = false)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#renderText">renderText</a></b>(int <i>x</i>, int <i>y</i>, const QString &amp;<i>str</i>, const QFont &amp;<i>font</i> = QFont())</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#renderText-1">renderText</a></b>(double <i>x</i>, double <i>y</i>, double <i>z</i>, const QString &amp;<i>str</i>, const QFont &amp;<i>font</i> = QFont())</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#setColormap">setColormap</a></b>(const QGLColormap &amp;<i>cmap</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#swapBuffers">swapBuffers</a></b>()</td></tr>
</table></div>
<ul>
<li class="fn">216 public functions inherited from <a href="../qtwidgets/qwidget.html#public-functions">QWidget</a></li>
<li class="fn">31 public functions inherited from <a href="../qtcore/qobject.html#public-functions">QObject</a></li>
<li class="fn">14 public functions inherited from <a href="../qtgui/qpaintdevice.html#public-functions">QPaintDevice</a></li>
</ul>
<a name="public-slots"></a>
<h2 id="public-slots">Public Slots</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#updateGL">updateGL</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#updateOverlayGL">updateOverlayGL</a></b>()</td></tr>
</table></div>
<ul>
<li class="fn">19 public slots inherited from <a href="../qtwidgets/qwidget.html#public-slots">QWidget</a></li>
<li class="fn">1 public slot inherited from <a href="../qtcore/qobject.html#public-slots">QObject</a></li>
</ul>
<a name="static-public-members"></a>
<h2 id="static-public-members">Static Public Members</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> QImage </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#convertToGLFormat">convertToGLFormat</a></b>(const QImage &amp;<i>img</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> const QMetaObject </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#staticMetaObject-var">staticMetaObject</a></b></td></tr>
</table></div>
<ul>
<li class="fn">5 static public members inherited from <a href="../qtwidgets/qwidget.html#static-public-members">QWidget</a></li>
<li class="fn">9 static public members inherited from <a href="../qtcore/qobject.html#static-public-members">QObject</a></li>
</ul>
<a name="protected-functions"></a>
<h2 id="protected-functions">Protected Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#autoBufferSwap">autoBufferSwap</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#glDraw">glDraw</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#glInit">glInit</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#initializeGL">initializeGL</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#initializeOverlayGL">initializeOverlayGL</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#paintGL">paintGL</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#paintOverlayGL">paintOverlayGL</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#resizeGL">resizeGL</a></b>(int <i>width</i>, int <i>height</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#resizeOverlayGL">resizeOverlayGL</a></b>(int <i>width</i>, int <i>height</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#setAutoBufferSwap">setAutoBufferSwap</a></b>(bool <i>on</i>)</td></tr>
</table></div>
<a name="reimplemented-protected-functions"></a>
<h2 id="reimplemented-protected-functions">Reimplemented Protected Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> virtual bool </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#event">event</a></b>(QEvent *<i>e</i>) override</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#paintEvent">paintEvent</a></b>(QPaintEvent *<i>event</i>) override</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qglwidget.html#resizeEvent">resizeEvent</a></b>(QResizeEvent *<i>event</i>) override</td></tr>
</table></div>
<ul>
<li class="fn">35 protected functions inherited from <a href="../qtwidgets/qwidget.html#protected-functions">QWidget</a></li>
<li class="fn">9 protected functions inherited from <a href="../qtcore/qobject.html#protected-functions">QObject</a></li>
<li class="fn">1 protected function inherited from <a href="../qtgui/qpaintdevice.html#protected-functions">QPaintDevice</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li class="fn">59 properties inherited from <a href="../qtwidgets/qwidget.html#properties">QWidget</a></li>
<li class="fn">1 property inherited from <a href="../qtcore/qobject.html#properties">QObject</a></li>
<li class="fn">3 signals inherited from <a href="../qtwidgets/qwidget.html#signals">QWidget</a></li>
<li class="fn">2 signals inherited from <a href="../qtcore/qobject.html#signals">QObject</a></li>
<li class="fn">1 protected slot inherited from <a href="../qtwidgets/qwidget.html#protected-slots">QWidget</a></li>
</ul>
<a name="details"></a>
<!-- $$$QGLWidget-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>The <a href="qglwidget.html">QGLWidget</a> class is a widget for rendering OpenGL graphics.</p>
<p><a href="qglwidget.html">QGLWidget</a> provides functionality for displaying OpenGL graphics integrated into a Qt application. It is very simple to use. You inherit from it and use the subclass like any other <a href="../qtwidgets/qwidget.html">QWidget</a>, except that you have the choice between using <a href="../qtgui/qpainter.html">QPainter</a> and standard OpenGL rendering commands.</p>
<p><b>Note: </b>This class is part of the legacy <a href="qtopengl-index.html">Qt OpenGL</a> module and, like the other <code>QGL</code> classes, should be avoided in the new applications. Instead, starting from Qt 5.4, prefer using <a href="../qtwidgets/qopenglwidget.html">QOpenGLWidget</a> and the <code>QOpenGL</code> classes.</p><p><a href="qglwidget.html">QGLWidget</a> provides three convenient virtual functions that you can reimplement in your subclass to perform the typical OpenGL tasks:</p>
<ul>
<li><a href="qglwidget.html#paintGL">paintGL</a>() - Renders the OpenGL scene. Gets called whenever the widget needs to be updated.</li>
<li><a href="qglwidget.html#resizeGL">resizeGL</a>() - Sets up the OpenGL viewport, projection, etc. Gets called whenever the widget has been resized (and also when it is shown for the first time because all newly created widgets get a resize event automatically).</li>
<li><a href="qglwidget.html#initializeGL">initializeGL</a>() - Sets up the OpenGL rendering context, defines display lists, etc. Gets called once before the first time <a href="qglwidget.html#resizeGL">resizeGL</a>() or <a href="qglwidget.html#paintGL">paintGL</a>() is called.</li>
</ul>
<p>Here is a rough outline of how a <a href="qglwidget.html">QGLWidget</a> subclass might look:</p>
<pre class="cpp">

  <span class="keyword">class</span> MyGLDrawer : <span class="keyword">public</span> <span class="type"><a href="qglwidget.html#QGLWidget">QGLWidget</a></span>
  {
      Q_OBJECT        <span class="comment">// must include this if you use Qt signals/slots</span>

  <span class="keyword">public</span>:
      MyGLDrawer(<span class="type"><a href="../qtwidgets/qwidget.html#QWidget">QWidget</a></span> <span class="operator">*</span>parent)
          : <span class="type"><a href="qglwidget.html#QGLWidget">QGLWidget</a></span>(parent) {}

  <span class="keyword">protected</span>:

      <span class="type">void</span> initializeGL() override
      {
          <span class="comment">// Set up the rendering context, define display lists etc.:</span>
          <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
          glClearColor(<span class="number">0.0</span><span class="operator">,</span> <span class="number">0.0</span><span class="operator">,</span> <span class="number">0.0</span><span class="operator">,</span> <span class="number">0.0</span>);
          glEnable(GL_DEPTH_TEST);
          <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
      }

      <span class="type">void</span> resizeGL(<span class="type">int</span> w<span class="operator">,</span> <span class="type">int</span> h) override
      {
          <span class="comment">// setup viewport, projection etc.:</span>
          glViewport(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> (GLint)w<span class="operator">,</span> (GLint)h);
          <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
          glFrustum(<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>);
          <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
      }

      <span class="type">void</span> paintGL() override
      {
          <span class="comment">// draw the scene:</span>
          <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
          glRotatef(<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>);
          glMaterialfv(<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>);
          glBegin(GL_QUADS);
          glVertex3f(<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>);
          glVertex3f(<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>);
          <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
          glEnd();
          <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
      }

  };

</pre>
<p>If you need to trigger a repaint from places other than <a href="qglwidget.html#paintGL">paintGL</a>() (a typical example is when using <a href="../qtcore/qtimer.html">timers</a> to animate scenes), you should call the widget's <a href="qglwidget.html#updateGL">updateGL</a>() function.</p>
<p>Your widget's OpenGL rendering context is made current when <a href="qglwidget.html#paintGL">paintGL</a>(), <a href="qglwidget.html#resizeGL">resizeGL</a>(), or <a href="qglwidget.html#initializeGL">initializeGL</a>() is called. If you need to call the standard OpenGL API functions from other places (e.g&#x2e; in your widget's constructor or in your own paint functions), you must call <a href="qglwidget.html#makeCurrent">makeCurrent</a>() first.</p>
<p><a href="qglwidget.html">QGLWidget</a> provides functions for requesting a new display <a href="qglformat.html">format</a> and you can also create widgets with customized rendering <a href="qglcontext.html">contexts</a>.</p>
<p>You can also share OpenGL display lists between <a href="qglwidget.html">QGLWidget</a> objects (see the documentation of the <a href="qglwidget.html">QGLWidget</a> constructors for details).</p>
<p>Note that under Windows, the <a href="qglcontext.html">QGLContext</a> belonging to a <a href="qglwidget.html">QGLWidget</a> has to be recreated when the <a href="qglwidget.html">QGLWidget</a> is reparented. This is necessary due to limitations on the Windows platform. This will most likely cause problems for users that have subclassed and installed their own <a href="qglcontext.html">QGLContext</a> on a <a href="qglwidget.html">QGLWidget</a>. It is possible to work around this issue by putting the <a href="qglwidget.html">QGLWidget</a> inside a dummy widget and then reparenting the dummy widget, instead of the <a href="qglwidget.html">QGLWidget</a>. This will side-step the issue altogether, and is what we recommend for users that need this kind of functionality.</p>
<p>On macOS, when Qt is built with Cocoa support, a <a href="qglwidget.html">QGLWidget</a> can't have any sibling widgets placed ontop of itself. This is due to limitations in the Cocoa API and is not supported by Apple.</p>
<a name="overlays"></a>
<h3 id="overlays">Overlays</h3>
<p>The <a href="qglwidget.html">QGLWidget</a> creates a GL overlay context in addition to the normal context if overlays are supported by the underlying system.</p>
<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 format passed to the <a href="qglwidget.html">QGLWidget</a> constructor.) Your GL widget should also implement some or all of these virtual methods:</p>
<ul>
<li><a href="qglwidget.html#paintOverlayGL">paintOverlayGL</a>()</li>
<li><a href="qglwidget.html#resizeOverlayGL">resizeOverlayGL</a>()</li>
<li><a href="qglwidget.html#initializeOverlayGL">initializeOverlayGL</a>()</li>
</ul>
<p>These methods work in the same way as the normal <a href="qglwidget.html#paintGL">paintGL</a>() etc. functions, except that they will be called when the overlay context is made current. You can explicitly make the overlay context current by using <a href="qglwidget.html#makeOverlayCurrent">makeOverlayCurrent</a>(), and you can access the overlay context directly (e.g&#x2e; to ask for its transparent color) by calling <a href="qglwidget.html#overlayContext">overlayContext</a>().</p>
<p>On X servers in which the default visual is in an overlay plane, non-GL Qt windows can also be used for overlays.</p>
<a name="painting-techniques"></a>
<h3 id="painting-techniques">Painting Techniques</h3>
<p>As described above, subclass <a href="qglwidget.html">QGLWidget</a> to render pure 3D content in the following way:</p>
<ul>
<li>Reimplement the <a href="qglwidget.html#initializeGL">QGLWidget::initializeGL</a>() and <a href="qglwidget.html#resizeGL">QGLWidget::resizeGL</a>() to set up the OpenGL state and provide a perspective transformation.</li>
<li>Reimplement <a href="qglwidget.html#paintGL">QGLWidget::paintGL</a>() to paint the 3D scene, calling only OpenGL functions to draw on the widget.</li>
</ul>
<p>It is also possible to draw 2D graphics onto a <a href="qglwidget.html">QGLWidget</a> subclass, it is necessary to reimplement <a href="qglwidget.html#paintEvent">QGLWidget::paintEvent</a>() and do the following:</p>
<ul>
<li>Construct a <a href="../qtgui/qpainter.html">QPainter</a> object.</li>
<li>Initialize it for use on the widget with the <a href="../qtgui/qpainter.html#begin">QPainter::begin</a>() function.</li>
<li>Draw primitives using <a href="../qtgui/qpainter.html">QPainter</a>'s member functions.</li>
<li>Call <a href="../qtgui/qpainter.html#end">QPainter::end</a>() to finish painting.</li>
</ul>
<a name="threading"></a>
<h3 id="threading">Threading</h3>
<p>As of Qt version 4.8, support for doing threaded GL rendering has been improved. There are three scenarios that we currently support:</p>
<ul>
<li>1. Buffer swapping in a thread.<p>Swapping buffers in a double buffered context may be a synchronous, locking call that may be a costly operation in some GL implementations. Especially so on embedded devices. It's not optimal to have the CPU idling while the GPU is doing a buffer swap. In those cases it is possible to do the rendering in the main thread and do the actual buffer swap in a separate thread. This can be done with the following steps:</p>
<p>1. Call <a href="qglwidget.html#doneCurrent">doneCurrent</a>() in the main thread when the rendering is finished.</p>
<p>2. Call <a href="qglcontext.html#moveToThread">QGLContext::moveToThread</a>(swapThread) to transfer ownership of the context to the swapping thread.</p>
<p>3. Notify the swapping thread that it can grab the context.</p>
<p>4. Make the rendering context current in the swapping thread with <a href="qglwidget.html#makeCurrent">makeCurrent</a>() and then call <a href="qglwidget.html#swapBuffers">swapBuffers</a>().</p>
<p>5. Call <a href="qglwidget.html#doneCurrent">doneCurrent</a>() in the swapping thread.</p>
<p>6. Call <a href="qglcontext.html#moveToThread">QGLContext::moveToThread</a>(<a href="../qtwidgets/qapplication.html#qApp">qApp</a>-&gt;<a href="../qtcore/qobject.html#thread">thread</a>()) and notify the main thread that swapping is done.</p>
<p>Doing this will free up the main thread so that it can continue with, for example, handling UI events or network requests. Even if there is a context swap involved, it may be preferable compared to having the main thread wait while the GPU finishes the swap operation. Note that this is highly implementation dependent.</p>
</li>
<li>2. Texture uploading in a thread.<p>Doing texture uploads in a thread may be very useful for applications handling large amounts of images that needs to be displayed, like for instance a photo gallery application. This is supported in Qt through the existing <a href="qglwidget.html#bindTexture">bindTexture</a>() API. A simple way of doing this is to create two sharing QGLWidgets. One is made current in the main GUI thread, while the other is made current in the texture upload thread. The widget in the uploading thread is never shown, it is only used for sharing textures with the main thread. For each texture that is bound via <a href="qglwidget.html#bindTexture">bindTexture</a>(), notify the main thread so that it can start using the texture.</p>
</li>
<li>3. Using <a href="../qtgui/qpainter.html">QPainter</a> to draw into a <a href="qglwidget.html">QGLWidget</a> in a thread.<p>In Qt 4.8, it is possible to draw into a <a href="qglwidget.html">QGLWidget</a> using a <a href="../qtgui/qpainter.html">QPainter</a> in a separate thread. Note that this is also possible for QGLPixelBuffers and QGLFramebufferObjects. Since this is only supported in the GL 2 paint engine, OpenGL 2.0 or OpenGL ES 2.0 is required.</p>
<p>QGLWidgets can only be created in the main GUI thread. This means a call to <a href="qglwidget.html#doneCurrent">doneCurrent</a>() is necessary to release the GL context from the main thread, before the widget can be drawn into by another thread. You then need to call <a href="qglcontext.html#moveToThread">QGLContext::moveToThread</a>() to transfer ownership of the context to the thread in which you want to make it current. Also, the main GUI thread will dispatch resize and paint events to a <a href="qglwidget.html">QGLWidget</a> when the widget is resized, or parts of it becomes exposed or needs redrawing. It is therefore necessary to handle those events because the default implementations inside <a href="qglwidget.html">QGLWidget</a> will try to make the <a href="qglwidget.html">QGLWidget</a>'s context current, which again will interfere with any threads rendering into the widget. Reimplement <a href="qglwidget.html#paintEvent">QGLWidget::paintEvent</a>() and <a href="qglwidget.html#resizeEvent">QGLWidget::resizeEvent</a>() to notify the rendering thread that a resize or update is necessary, and be careful not to call the base class implementation. If you are rendering an animation, it might not be necessary to handle the paint event at all since the rendering thread is doing regular updates. Then it would be enough to reimplement <a href="qglwidget.html#paintEvent">QGLWidget::paintEvent</a>() to do nothing.</p>
</li>
</ul>
<p>As a general rule when doing threaded rendering: be aware that binding and releasing contexts in different threads have to be synchronized by the user. A GL rendering context can only be current in one thread at any time. If you try to open a <a href="../qtgui/qpainter.html">QPainter</a> on a <a href="qglwidget.html">QGLWidget</a> and the widget's rendering context is current in another thread, it will fail.</p>
<p>In addition to this, rendering using raw GL calls in a separate thread is supported.</p>
<p><i>OpenGL is a trademark of Silicon Graphics, Inc. in the United States and other countries.</i></p>
</div>
<p><b>See also </b><a href="../qtwidgets/qopenglwidget.html">QOpenGLWidget</a> and <a href="qglpixelbuffer.html">QGLPixelBuffer</a>.</p>
<!-- @@@QGLWidget -->
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QGLWidget[overload1]$$$QGLWidgetQWidget*constQGLWidget*Qt::WindowFlags -->
<h3 class="fn" id="QGLWidget"><a name="QGLWidget"></a>QGLWidget::<span class="name">QGLWidget</span>(<span class="type"><a href="../qtwidgets/qwidget.html#QWidget">QWidget</a></span> *<i>parent</i> = nullptr, const <span class="type"><a href="qglwidget.html#QGLWidget">QGLWidget</a></span> *<i>shareWidget</i> = nullptr, <span class="type"><a href="../qtcore/qt.html#WindowType-enum">Qt::WindowFlags</a></span> <i>f</i> = ...)</h3>
<p>Constructs an OpenGL widget with a <i>parent</i> widget.</p>
<p>The <a href="qglformat.html#defaultFormat">default format</a> is used. The widget will be <a href="qglwidget.html#isValid">invalid</a> if the system has no <a href="qglformat.html#hasOpenGL">OpenGL support</a>.</p>
<p>The <i>parent</i> and widget flag, <i>f</i>, arguments are passed to the <a href="../qtwidgets/qwidget.html">QWidget</a> constructor.</p>
<p>If <i>shareWidget</i> is a valid <a href="qglwidget.html" class="obsolete">QGLWidget</a>, this widget will share OpenGL display lists and texture objects with <i>shareWidget</i>. But if <i>shareWidget</i> and this widget have different <a href="qglwidget.html#format">formats</a>, sharing might not be possible. You can check whether sharing is in effect by calling <a href="qglwidget.html#isSharing">isSharing</a>().</p>
<p>The initialization of OpenGL rendering state, etc. should be done by overriding the <a href="qglwidget.html#initializeGL">initializeGL</a>() function, rather than in the constructor of your <a href="qglwidget.html" class="obsolete">QGLWidget</a> subclass.</p>
<p><b>See also </b><a href="qglformat.html#defaultFormat">QGLFormat::defaultFormat</a>() and <a href="qtopengl-textures-example.html">Textures Example</a>.</p>
<!-- @@@QGLWidget -->
<!-- $$$QGLWidget$$$QGLWidgetQGLContext*QWidget*constQGLWidget*Qt::WindowFlags -->
<h3 class="fn" id="QGLWidget-1"><a name="QGLWidget-1"></a>QGLWidget::<span class="name">QGLWidget</span>(<span class="type"><a href="qglcontext.html">QGLContext</a></span> *<i>context</i>, <span class="type"><a href="../qtwidgets/qwidget.html#QWidget">QWidget</a></span> *<i>parent</i> = nullptr, const <span class="type"><a href="qglwidget.html#QGLWidget">QGLWidget</a></span> *<i>shareWidget</i> = nullptr, <span class="type"><a href="../qtcore/qt.html#WindowType-enum">Qt::WindowFlags</a></span> <i>f</i> = ...)</h3>
<p>Constructs an OpenGL widget with parent <i>parent</i>.</p>
<p>The <i>context</i> argument is a pointer to the QGLContext that you wish to be bound to this widget. This allows you to pass in your own QGLContext sub-classes.</p>
<p>The widget will be <a href="qglwidget.html#isValid">invalid</a> if the system has no <a href="qglformat.html#hasOpenGL">OpenGL support</a>.</p>
<p>The <i>parent</i> and widget flag, <i>f</i>, arguments are passed to the <a href="../qtwidgets/qwidget.html">QWidget</a> constructor.</p>
<p>If <i>shareWidget</i> is a valid <a href="qglwidget.html" class="obsolete">QGLWidget</a>, this widget will share OpenGL display lists and texture objects with <i>shareWidget</i>. But if <i>shareWidget</i> and this widget have different <a href="qglwidget.html#format">formats</a>, sharing might not be possible. You can check whether sharing is in effect by calling <a href="qglwidget.html#isSharing">isSharing</a>().</p>
<p>The initialization of OpenGL rendering state, etc. should be done by overriding the <a href="qglwidget.html#initializeGL">initializeGL</a>() function, rather than in the constructor of your <a href="qglwidget.html" class="obsolete">QGLWidget</a> subclass.</p>
<p><b>See also </b><a href="qglformat.html#defaultFormat">QGLFormat::defaultFormat</a>() and <a href="qglwidget.html#isValid">isValid</a>().</p>
<!-- @@@QGLWidget -->
<!-- $$$QGLWidget$$$QGLWidgetconstQGLFormat&QWidget*constQGLWidget*Qt::WindowFlags -->
<h3 class="fn" id="QGLWidget-2"><a name="QGLWidget-2"></a>QGLWidget::<span class="name">QGLWidget</span>(const <span class="type"><a href="qglformat.html">QGLFormat</a></span> &amp;<i>format</i>, <span class="type"><a href="../qtwidgets/qwidget.html#QWidget">QWidget</a></span> *<i>parent</i> = nullptr, const <span class="type"><a href="qglwidget.html#QGLWidget">QGLWidget</a></span> *<i>shareWidget</i> = nullptr, <span class="type"><a href="../qtcore/qt.html#WindowType-enum">Qt::WindowFlags</a></span> <i>f</i> = ...)</h3>
<p>Constructs an OpenGL widget with parent <i>parent</i>.</p>
<p>The <i>format</i> argument specifies the desired <a href="qglformat.html">rendering options</a>. If the underlying OpenGL/Window system cannot satisfy all the features requested in <i>format</i>, the nearest subset of features will be used. After creation, the <a href="qglwidget.html#format">format</a>() method will return the actual format obtained.</p>
<p>The widget will be <a href="qglwidget.html#isValid">invalid</a> if the system has no <a href="qglformat.html#hasOpenGL">OpenGL support</a>.</p>
<p>The <i>parent</i> and widget flag, <i>f</i>, arguments are passed to the <a href="../qtwidgets/qwidget.html">QWidget</a> constructor.</p>
<p>If <i>shareWidget</i> is a valid <a href="qglwidget.html" class="obsolete">QGLWidget</a>, this widget will share OpenGL display lists and texture objects with <i>shareWidget</i>. But if <i>shareWidget</i> and this widget have different <a href="qglwidget.html#format">formats</a>, sharing might not be possible. You can check whether sharing is in effect by calling <a href="qglwidget.html#isSharing">isSharing</a>().</p>
<p>The initialization of OpenGL rendering state, etc. should be done by overriding the <a href="qglwidget.html#initializeGL">initializeGL</a>() function, rather than in the constructor of your <a href="qglwidget.html" class="obsolete">QGLWidget</a> subclass.</p>
<p><b>See also </b><a href="qglformat.html#defaultFormat">QGLFormat::defaultFormat</a>() and <a href="qglwidget.html#isValid">isValid</a>().</p>
<!-- @@@QGLWidget -->
<!-- $$$~QGLWidget[overload1]$$$~QGLWidget -->
<h3 class="fn" id="dtor.QGLWidget"><a name="dtor.QGLWidget"></a><code>[virtual] </code>QGLWidget::<span class="name">~QGLWidget</span>()</h3>
<p>Destroys the widget.</p>
<!-- @@@~QGLWidget -->
<!-- $$$autoBufferSwap[overload1]$$$autoBufferSwap -->
<h3 class="fn" id="autoBufferSwap"><a name="autoBufferSwap"></a><code>[protected] </code><span class="type">bool</span> QGLWidget::<span class="name">autoBufferSwap</span>() const</h3>
<p>Returns <code>true</code> if the widget is doing automatic GL buffer swapping; otherwise returns <code>false</code>.</p>
<p><b>See also </b><a href="qglwidget.html#setAutoBufferSwap">setAutoBufferSwap</a>().</p>
<!-- @@@autoBufferSwap -->
<!-- $$$bindTexture[overload1]$$$bindTextureconstQImage&GLenumGLint -->
<h3 class="fn" id="bindTexture"><a name="bindTexture"></a><span class="type">GLuint</span> QGLWidget::<span class="name">bindTexture</span>(const <span class="type"><a href="../qtgui/qimage.html">QImage</a></span> &amp;<i>image</i>, <span class="type">GLenum</span> <i>target</i> = GL_TEXTURE_2D, <span class="type">GLint</span> <i>format</i> = GL_RGBA)</h3>
<p>Calls QGLContext:::bindTexture(<i>image</i>, <i>target</i>, <i>format</i>) on the currently set context.</p>
<p><b>See also </b><a href="qglwidget.html#deleteTexture">deleteTexture</a>().</p>
<!-- @@@bindTexture -->
<!-- $$$bindTexture$$$bindTextureconstQPixmap&GLenumGLintQGLContext::BindOptions -->
<h3 class="fn" id="bindTexture-1"><a name="bindTexture-1"></a><span class="type">GLuint</span> QGLWidget::<span class="name">bindTexture</span>(const <span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span> &amp;<i>pixmap</i>, <span class="type">GLenum</span> <i>target</i>, <span class="type">GLint</span> <i>format</i>, <span class="type"><a href="qglcontext.html#BindOption-enum">QGLContext::BindOptions</a></span> <i>options</i>)</h3>
<p>This is an overloaded function.</p>
<p>Generates and binds a 2D GL texture to the current context, based on <i>pixmap</i>. The generated texture id is returned and can be used in</p>
<p>The binding <i>options</i> are a set of options used to decide how to bind the texture to the context.</p>
<p>This function was introduced in  Qt 4.6.</p>
<!-- @@@bindTexture -->
<!-- $$$bindTexture$$$bindTextureconstQImage&GLenumGLintQGLContext::BindOptions -->
<h3 class="fn" id="bindTexture-2"><a name="bindTexture-2"></a><span class="type">GLuint</span> QGLWidget::<span class="name">bindTexture</span>(const <span class="type"><a href="../qtgui/qimage.html">QImage</a></span> &amp;<i>image</i>, <span class="type">GLenum</span> <i>target</i>, <span class="type">GLint</span> <i>format</i>, <span class="type"><a href="qglcontext.html#BindOption-enum">QGLContext::BindOptions</a></span> <i>options</i>)</h3>
<p>This is an overloaded function.</p>
<p>The binding <i>options</i> are a set of options used to decide how to bind the texture to the context.</p>
<p>This function was introduced in  Qt 4.6.</p>
<!-- @@@bindTexture -->
<!-- $$$bindTexture$$$bindTextureconstQPixmap&GLenumGLint -->
<h3 class="fn" id="bindTexture-3"><a name="bindTexture-3"></a><span class="type">GLuint</span> QGLWidget::<span class="name">bindTexture</span>(const <span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span> &amp;<i>pixmap</i>, <span class="type">GLenum</span> <i>target</i> = GL_TEXTURE_2D, <span class="type">GLint</span> <i>format</i> = GL_RGBA)</h3>
<p>Calls QGLContext:::<a href="qglwidget.html#bindTexture">bindTexture</a>(<i>pixmap</i>, <i>target</i>, <i>format</i>) on the currently set context.</p>
<p><b>See also </b><a href="qglwidget.html#deleteTexture">deleteTexture</a>().</p>
<!-- @@@bindTexture -->
<!-- $$$bindTexture$$$bindTextureconstQString& -->
<h3 class="fn" id="bindTexture-4"><a name="bindTexture-4"></a><span class="type">GLuint</span> QGLWidget::<span class="name">bindTexture</span>(const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>fileName</i>)</h3>
<p>This is an overloaded function.</p>
<p>Calls <a href="qglcontext.html#bindTexture">QGLContext::bindTexture</a>(<i>fileName</i>) on the currently set context.</p>
<p><b>See also </b><a href="qglwidget.html#deleteTexture">deleteTexture</a>().</p>
<!-- @@@bindTexture -->
<!-- $$$colormap[overload1]$$$colormap -->
<h3 class="fn" id="colormap"><a name="colormap"></a>const <span class="type"><a href="qglcolormap.html">QGLColormap</a></span> &amp;QGLWidget::<span class="name">colormap</span>() const</h3>
<p>Returns the colormap for this widget.</p>
<p>Usually it is only top-level widgets that can have different colormaps installed. Asking for the colormap of a child widget will return the colormap for the child's top-level widget.</p>
<p>If no colormap has been set for this widget, the QGLColormap returned will be empty.</p>
<p><b>See also </b><a href="qglwidget.html#setColormap">setColormap</a>() and <a href="qglcolormap.html#isEmpty">QGLColormap::isEmpty</a>().</p>
<!-- @@@colormap -->
<!-- $$$context[overload1]$$$context -->
<h3 class="fn" id="context"><a name="context"></a><span class="type"><a href="qglcontext.html">QGLContext</a></span> *QGLWidget::<span class="name">context</span>() const</h3>
<p>Returns the context of this widget.</p>
<p>It is possible that the context is not valid (see <a href="qglwidget.html#isValid">isValid</a>()), for example, if the underlying hardware does not support the format attributes that were requested.</p>
<p><b>See also </b><a href="qglwidget-obsolete.html#setContext">setContext</a>().</p>
<!-- @@@context -->
<!-- $$$convertToGLFormat[overload1]$$$convertToGLFormatconstQImage& -->
<h3 class="fn" id="convertToGLFormat"><a name="convertToGLFormat"></a><code>[static] </code><span class="type"><a href="../qtgui/qimage.html">QImage</a></span> QGLWidget::<span class="name">convertToGLFormat</span>(const <span class="type"><a href="../qtgui/qimage.html">QImage</a></span> &amp;<i>img</i>)</h3>
<p>Converts the image <i>img</i> into the unnamed format expected by OpenGL functions such as glTexImage2D(). The returned image is not usable as a <a href="../qtgui/qimage.html">QImage</a>, but <a href="../qtgui/qimage.html#width">QImage::width</a>(), <a href="../qtgui/qimage.html#height">QImage::height</a>() and <a href="../qtgui/qimage.html#bits">QImage::bits</a>() may be used with OpenGL. The GL format used is <code>GL_RGBA</code>.</p>
<!-- @@@convertToGLFormat -->
<!-- $$$deleteTexture[overload1]$$$deleteTextureGLuint -->
<h3 class="fn" id="deleteTexture"><a name="deleteTexture"></a><span class="type">void</span> QGLWidget::<span class="name">deleteTexture</span>(<span class="type">GLuint</span> <i>id</i>)</h3>
<p>Calls <a href="qglcontext.html#deleteTexture">QGLContext::deleteTexture</a>(<i>id</i>) on the currently set context.</p>
<p><b>See also </b><a href="qglwidget.html#bindTexture">bindTexture</a>().</p>
<!-- @@@deleteTexture -->
<!-- $$$doneCurrent[overload1]$$$doneCurrent -->
<h3 class="fn" id="doneCurrent"><a name="doneCurrent"></a><span class="type">void</span> QGLWidget::<span class="name">doneCurrent</span>()</h3>
<p>Makes no GL context the current context. Normally, you do not need to call this function; QGLContext calls it as necessary. However, it may be useful in multithreaded environments.</p>
<!-- @@@doneCurrent -->
<!-- $$$doubleBuffer[overload1]$$$doubleBuffer -->
<h3 class="fn" id="doubleBuffer"><a name="doubleBuffer"></a><span class="type">bool</span> QGLWidget::<span class="name">doubleBuffer</span>() const</h3>
<p>Returns <code>true</code> if the contained GL rendering context has double buffering; otherwise returns <code>false</code>.</p>
<p><b>See also </b><a href="qglformat.html#doubleBuffer">QGLFormat::doubleBuffer</a>().</p>
<!-- @@@doubleBuffer -->
<!-- $$$drawTexture[overload1]$$$drawTextureconstQRectF&GLuintGLenum -->
<h3 class="fn" id="drawTexture"><a name="drawTexture"></a><span class="type">void</span> QGLWidget::<span class="name">drawTexture</span>(const <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span> &amp;<i>target</i>, <span class="type">GLuint</span> <i>textureId</i>, <span class="type">GLenum</span> <i>textureTarget</i> = GL_TEXTURE_2D)</h3>
<p>Calls the corresponding <a href="qglcontext.html#drawTexture">QGLContext::drawTexture</a>() with <i>target</i>, <i>textureId</i>, and <i>textureTarget</i> for this widget's context.</p>
<p>This function was introduced in  Qt 4.4.</p>
<!-- @@@drawTexture -->
<!-- $$$drawTexture$$$drawTextureconstQPointF&GLuintGLenum -->
<h3 class="fn" id="drawTexture-1"><a name="drawTexture-1"></a><span class="type">void</span> QGLWidget::<span class="name">drawTexture</span>(const <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span> &amp;<i>point</i>, <span class="type">GLuint</span> <i>textureId</i>, <span class="type">GLenum</span> <i>textureTarget</i> = GL_TEXTURE_2D)</h3>
<p>Calls the corresponding <a href="qglcontext.html#drawTexture">QGLContext::drawTexture</a>() with <i>point</i>, <i>textureId</i>, and <i>textureTarget</i> for this widget's context.</p>
<p>This function was introduced in  Qt 4.4.</p>
<!-- @@@drawTexture -->
<!-- $$$event[overload1]$$$eventQEvent* -->
<h3 class="fn" id="event"><a name="event"></a><code>[override virtual protected] </code><span class="type">bool</span> QGLWidget::<span class="name">event</span>(<span class="type"><a href="../qtcore/qevent.html">QEvent</a></span> *<i>e</i>)</h3>
<p>Reimplemented from <a href="../qtwidgets/qwidget.html#event">QWidget::event</a>().</p>
<!-- @@@event -->
<!-- $$$format[overload1]$$$format -->
<h3 class="fn" id="format"><a name="format"></a><span class="type"><a href="qglformat.html">QGLFormat</a></span> QGLWidget::<span class="name">format</span>() const</h3>
<p>Returns the format of the contained GL rendering context.</p>
<p><b>See also </b><a href="qglwidget-obsolete.html#setFormat">setFormat</a>().</p>
<!-- @@@format -->
<!-- $$$glDraw[overload1]$$$glDraw -->
<h3 class="fn" id="glDraw"><a name="glDraw"></a><code>[virtual protected] </code><span class="type">void</span> QGLWidget::<span class="name">glDraw</span>()</h3>
<p>Executes the virtual function <a href="qglwidget.html#paintGL">paintGL</a>().</p>
<p>The widget's rendering context will become the current context and <a href="qglwidget.html#initializeGL">initializeGL</a>() will be called if it hasn't already been called.</p>
<!-- @@@glDraw -->
<!-- $$$glInit[overload1]$$$glInit -->
<h3 class="fn" id="glInit"><a name="glInit"></a><code>[virtual protected] </code><span class="type">void</span> QGLWidget::<span class="name">glInit</span>()</h3>
<p>Initializes OpenGL for this widget's context. Calls the virtual function <a href="qglwidget.html#initializeGL">initializeGL</a>().</p>
<!-- @@@glInit -->
<!-- $$$grabFrameBuffer[overload1]$$$grabFrameBufferbool -->
<h3 class="fn" id="grabFrameBuffer"><a name="grabFrameBuffer"></a><span class="type"><a href="../qtgui/qimage.html">QImage</a></span> QGLWidget::<span class="name">grabFrameBuffer</span>(<span class="type">bool</span> <i>withAlpha</i> = false)</h3>
<p>Returns an image of the frame buffer. If <i>withAlpha</i> is true the alpha channel is included.</p>
<p>Depending on your hardware, you can explicitly select which color buffer to grab with a glReadBuffer() call before calling this function.</p>
<p>On QNX the back buffer is not preserved when <a href="qglwidget.html#swapBuffers">swapBuffers</a>() is called. The back buffer where this function reads from, might thus not contain the same content as the front buffer. In order to retrieve what is currently visible on the screen, <a href="qglwidget.html#swapBuffers">swapBuffers</a>() has to be executed prior to this function call.</p>
<!-- @@@grabFrameBuffer -->
<!-- $$$initializeGL[overload1]$$$initializeGL -->
<h3 class="fn" id="initializeGL"><a name="initializeGL"></a><code>[virtual protected] </code><span class="type">void</span> QGLWidget::<span class="name">initializeGL</span>()</h3>
<p>This virtual function is called once before the first call to <a href="qglwidget.html#paintGL">paintGL</a>() or <a href="qglwidget.html#resizeGL">resizeGL</a>(), and then once whenever the widget has been assigned a new QGLContext. Reimplement it in a subclass.</p>
<p>This function should set up any required OpenGL context rendering flags, defining display lists, etc.</p>
<p>There is no need to call <a href="qglwidget.html#makeCurrent">makeCurrent</a>() because this has already been done when this function is called.</p>
<!-- @@@initializeGL -->
<!-- $$$initializeOverlayGL[overload1]$$$initializeOverlayGL -->
<h3 class="fn" id="initializeOverlayGL"><a name="initializeOverlayGL"></a><code>[virtual protected] </code><span class="type">void</span> QGLWidget::<span class="name">initializeOverlayGL</span>()</h3>
<p>This virtual function is used in the same manner as <a href="qglwidget.html#initializeGL">initializeGL</a>() except that it operates on the widget's overlay context instead of the widget's main context. This means that initializeOverlayGL() is called once before the first call to <a href="qglwidget.html#paintOverlayGL">paintOverlayGL</a>() or <a href="qglwidget.html#resizeOverlayGL">resizeOverlayGL</a>(). Reimplement it in a subclass.</p>
<p>This function should set up any required OpenGL context rendering flags, defining display lists, etc. for the overlay context.</p>
<p>There is no need to call <a href="qglwidget.html#makeOverlayCurrent">makeOverlayCurrent</a>() because this has already been done when this function is called.</p>
<!-- @@@initializeOverlayGL -->
<!-- $$$isSharing[overload1]$$$isSharing -->
<h3 class="fn" id="isSharing"><a name="isSharing"></a><span class="type">bool</span> QGLWidget::<span class="name">isSharing</span>() const</h3>
<p>Returns <code>true</code> if this widget's GL context is shared with another GL context, otherwise false is returned. Context sharing might not be possible if the widgets use different formats.</p>
<p><b>See also </b><a href="qglwidget.html#format">format</a>().</p>
<!-- @@@isSharing -->
<!-- $$$isValid[overload1]$$$isValid -->
<h3 class="fn" id="isValid"><a name="isValid"></a><span class="type">bool</span> QGLWidget::<span class="name">isValid</span>() const</h3>
<p>Returns <code>true</code> if the widget has a valid GL rendering context; otherwise returns <code>false</code>. A widget will be invalid if the system has no <a href="qglformat.html#hasOpenGL">OpenGL support</a>.</p>
<!-- @@@isValid -->
<!-- $$$makeCurrent[overload1]$$$makeCurrent -->
<h3 class="fn" id="makeCurrent"><a name="makeCurrent"></a><span class="type">void</span> QGLWidget::<span class="name">makeCurrent</span>()</h3>
<p>Makes this widget the current widget for OpenGL operations, i.e&#x2e; makes the widget's rendering context the current OpenGL rendering context.</p>
<!-- @@@makeCurrent -->
<!-- $$$makeOverlayCurrent[overload1]$$$makeOverlayCurrent -->
<h3 class="fn" id="makeOverlayCurrent"><a name="makeOverlayCurrent"></a><span class="type">void</span> QGLWidget::<span class="name">makeOverlayCurrent</span>()</h3>
<p>Makes the overlay context of this widget current. Use this if you need to issue OpenGL commands to the overlay context outside of <a href="qglwidget.html#initializeOverlayGL">initializeOverlayGL</a>(), <a href="qglwidget.html#resizeOverlayGL">resizeOverlayGL</a>(), and <a href="qglwidget.html#paintOverlayGL">paintOverlayGL</a>().</p>
<p>Does nothing if this widget has no overlay.</p>
<p><b>See also </b><a href="qglwidget.html#makeCurrent">makeCurrent</a>().</p>
<!-- @@@makeOverlayCurrent -->
<!-- $$$overlayContext[overload1]$$$overlayContext -->
<h3 class="fn" id="overlayContext"><a name="overlayContext"></a>const <span class="type"><a href="qglcontext.html">QGLContext</a></span> *QGLWidget::<span class="name">overlayContext</span>() const</h3>
<p>Returns the overlay context of this widget, or 0 if this widget has no overlay.</p>
<p><b>See also </b><a href="qglwidget.html#context">context</a>().</p>
<!-- @@@overlayContext -->
<!-- $$$paintEvent[overload1]$$$paintEventQPaintEvent* -->
<h3 class="fn" id="paintEvent"><a name="paintEvent"></a><code>[override virtual protected] </code><span class="type">void</span> QGLWidget::<span class="name">paintEvent</span>(<span class="type"><a href="../qtgui/qpaintevent.html">QPaintEvent</a></span> *<i>event</i>)</h3>
<p>Reimplemented from <a href="../qtwidgets/qwidget.html#paintEvent">QWidget::paintEvent</a>().</p>
<p>Handles paint events passed in the <i>event</i> parameter. Will cause the virtual <a href="qglwidget.html#paintGL">paintGL</a>() function to be called.</p>
<p>The widget's rendering context will become the current context and <a href="qglwidget.html#initializeGL">initializeGL</a>() will be called if it hasn't already been called.</p>
<!-- @@@paintEvent -->
<!-- $$$paintGL[overload1]$$$paintGL -->
<h3 class="fn" id="paintGL"><a name="paintGL"></a><code>[virtual protected] </code><span class="type">void</span> QGLWidget::<span class="name">paintGL</span>()</h3>
<p>This virtual function is called whenever the widget needs to be painted. Reimplement it in a subclass.</p>
<p>There is no need to call <a href="qglwidget.html#makeCurrent">makeCurrent</a>() because this has already been done when this function is called.</p>
<!-- @@@paintGL -->
<!-- $$$paintOverlayGL[overload1]$$$paintOverlayGL -->
<h3 class="fn" id="paintOverlayGL"><a name="paintOverlayGL"></a><code>[virtual protected] </code><span class="type">void</span> QGLWidget::<span class="name">paintOverlayGL</span>()</h3>
<p>This virtual function is used in the same manner as <a href="qglwidget.html#paintGL">paintGL</a>() except that it operates on the widget's overlay context instead of the widget's main context. This means that paintOverlayGL() is called whenever the widget's overlay needs to be painted. Reimplement it in a subclass.</p>
<p>There is no need to call <a href="qglwidget.html#makeOverlayCurrent">makeOverlayCurrent</a>() because this has already been done when this function is called.</p>
<!-- @@@paintOverlayGL -->
<!-- $$$qglClearColor[overload1]$$$qglClearColorconstQColor& -->
<h3 class="fn" id="qglClearColor"><a name="qglClearColor"></a><span class="type">void</span> QGLWidget::<span class="name">qglClearColor</span>(const <span class="type"><a href="../qtgui/qcolor.html">QColor</a></span> &amp;<i>c</i>) const</h3>
<p>Convenience function for specifying the clearing color to OpenGL. Calls glClearColor (in RGBA mode) or glClearIndex (in color-index mode) with the color <i>c</i>. Applies to this widgets GL context.</p>
<p><b>See also </b><a href="qglwidget.html#qglColor">qglColor</a>(), <a href="qglcontext.html#currentContext">QGLContext::currentContext</a>(), and <a href="../qtgui/qcolor.html">QColor</a>.</p>
<!-- @@@qglClearColor -->
<!-- $$$qglColor[overload1]$$$qglColorconstQColor& -->
<h3 class="fn" id="qglColor"><a name="qglColor"></a><span class="type">void</span> QGLWidget::<span class="name">qglColor</span>(const <span class="type"><a href="../qtgui/qcolor.html">QColor</a></span> &amp;<i>c</i>) const</h3>
<p>Convenience function for specifying a drawing color to OpenGL. Calls glColor4 (in RGBA mode) or glIndex (in color-index mode) with the color <i>c</i>. Applies to this widgets GL context.</p>
<p><b>Note: </b>This function is not supported on OpenGL/ES 2.0 systems.</p><p><b>See also </b><a href="qglwidget.html#qglClearColor">qglClearColor</a>(), <a href="qglcontext.html#currentContext">QGLContext::currentContext</a>(), and <a href="../qtgui/qcolor.html">QColor</a>.</p>
<!-- @@@qglColor -->
<!-- $$$renderPixmap[overload1]$$$renderPixmapintintbool -->
<h3 class="fn" id="renderPixmap"><a name="renderPixmap"></a><span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span> QGLWidget::<span class="name">renderPixmap</span>(<span class="type">int</span> <i>w</i> = 0, <span class="type">int</span> <i>h</i> = 0, <span class="type">bool</span> <i>useContext</i> = false)</h3>
<p>Renders the current scene on a pixmap and returns the pixmap.</p>
<p>You can use this method on both visible and invisible <a href="qglwidget.html" class="obsolete">QGLWidget</a> objects.</p>
<p>Internally the function renders into a framebuffer object and performs pixel readback. This has a performance penalty, meaning that this function is not suitable to be called at a high frequency.</p>
<p>After creating and binding the framebuffer object, the function will call <a href="qglwidget.html#initializeGL">initializeGL</a>(), <a href="qglwidget.html#resizeGL">resizeGL</a>(), and <a href="qglwidget.html#paintGL">paintGL</a>(). On the next normal update <a href="qglwidget.html#initializeGL">initializeGL</a>() and <a href="qglwidget.html#resizeGL">resizeGL</a>() will be triggered again since the size of the destination pixmap and the <a href="qglwidget.html" class="obsolete">QGLWidget</a>'s size may differ.</p>
<p>The size of the pixmap will be <i>w</i> pixels wide and <i>h</i> pixels high unless one of these parameters is 0 (the default), in which case the pixmap will have the same size as the widget.</p>
<p>Care must be taken when using framebuffer objects in <a href="qglwidget.html#paintGL">paintGL</a>() in combination with this function. To switch back to the default framebuffer, use <a href="qglframebufferobject.html#bindDefault">QGLFramebufferObject::bindDefault</a>(). Binding FBO 0 is wrong since renderPixmap() uses a custom framebuffer instead of the one provided by the windowing system.</p>
<p><i>useContext</i> is ignored. Historically this parameter enabled the usage of the existing GL context. This is not supported anymore since additional contexts are never created.</p>
<p>Overlays are not rendered onto the pixmap.</p>
<p>If the GL rendering context and the desktop have different bit depths, the result will most likely look surprising.</p>
<p>Note that the creation of display lists, modifications of the view frustum etc. should be done from within <a href="qglwidget.html#initializeGL">initializeGL</a>(). If this is not done, the temporary QGLContext will not be initialized properly, and the rendered pixmap may be incomplete/corrupted.</p>
<!-- @@@renderPixmap -->
<!-- $$$renderText[overload1]$$$renderTextintintconstQString&constQFont& -->
<h3 class="fn" id="renderText"><a name="renderText"></a><span class="type">void</span> QGLWidget::<span class="name">renderText</span>(<span class="type">int</span> <i>x</i>, <span class="type">int</span> <i>y</i>, const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>str</i>, const <span class="type"><a href="../qtgui/qfont.html">QFont</a></span> &amp;<i>font</i> = QFont())</h3>
<p>Renders the string <i>str</i> into the GL context of this widget.</p>
<p><i>x</i> and <i>y</i> are specified in window coordinates, with the origin in the upper left-hand corner of the window. If <i>font</i> is not specified, the currently set application font will be used to render the string. To change the color of the rendered text you can use the glColor() call (or the <a href="qglwidget.html#qglColor">qglColor</a>() convenience function), just before the renderText() call.</p>
<p><b>Note: </b>This function clears the stencil buffer.</p><p><b>Note: </b>This function is not supported on OpenGL/ES systems.</p><p><b>Note: </b>This function temporarily disables depth-testing when the text is drawn.</p><p><b>Note: </b>This function can only be used inside a <a href="../qtgui/qpainter.html#beginNativePainting">QPainter::beginNativePainting</a>()/<a href="../qtgui/qpainter.html#endNativePainting">QPainter::endNativePainting</a>() block if a painter is active on the <a href="qglwidget.html" class="obsolete">QGLWidget</a>.</p><!-- @@@renderText -->
<!-- $$$renderText$$$renderTextdoubledoubledoubleconstQString&constQFont& -->
<h3 class="fn" id="renderText-1"><a name="renderText-1"></a><span class="type">void</span> QGLWidget::<span class="name">renderText</span>(<span class="type">double</span> <i>x</i>, <span class="type">double</span> <i>y</i>, <span class="type">double</span> <i>z</i>, const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>str</i>, const <span class="type"><a href="../qtgui/qfont.html">QFont</a></span> &amp;<i>font</i> = QFont())</h3>
<p>This is an overloaded function.</p>
<p><i>x</i>, <i>y</i> and <i>z</i> are specified in scene or object coordinates relative to the currently set projection and model matrices. This can be useful if you want to annotate models with text labels and have the labels move with the model as it is rotated etc.</p>
<p><b>Note: </b>This function is not supported on OpenGL/ES systems.</p><p><b>Note: </b>If depth testing is enabled before this function is called, then the drawn text will be depth-tested against the models that have already been drawn in the scene. Use <code>glDisable(GL_DEPTH_TEST)</code> before calling this function to annotate the models without depth-testing the text.</p><p><b>Note: </b>This function can only be used inside a <a href="../qtgui/qpainter.html#beginNativePainting">QPainter::beginNativePainting</a>()/<a href="../qtgui/qpainter.html#endNativePainting">QPainter::endNativePainting</a>() block if a painter is active on the <a href="qglwidget.html" class="obsolete">QGLWidget</a>.</p><!-- @@@renderText -->
<!-- $$$resizeEvent[overload1]$$$resizeEventQResizeEvent* -->
<h3 class="fn" id="resizeEvent"><a name="resizeEvent"></a><code>[override virtual protected] </code><span class="type">void</span> QGLWidget::<span class="name">resizeEvent</span>(<span class="type"><a href="../qtgui/qresizeevent.html">QResizeEvent</a></span> *<i>event</i>)</h3>
<p>Reimplemented from <a href="../qtwidgets/qwidget.html#resizeEvent">QWidget::resizeEvent</a>().</p>
<p>Handles resize events that are passed in the <i>event</i> parameter. Calls the virtual function <a href="qglwidget.html#resizeGL">resizeGL</a>().</p>
<!-- @@@resizeEvent -->
<!-- $$$resizeGL[overload1]$$$resizeGLintint -->
<h3 class="fn" id="resizeGL"><a name="resizeGL"></a><code>[virtual protected] </code><span class="type">void</span> QGLWidget::<span class="name">resizeGL</span>(<span class="type">int</span> <i>width</i>, <span class="type">int</span> <i>height</i>)</h3>
<p>This virtual function is called whenever the widget has been resized. The new size is passed in <i>width</i> and <i>height</i>. Reimplement it in a subclass.</p>
<p>There is no need to call <a href="qglwidget.html#makeCurrent">makeCurrent</a>() because this has already been done when this function is called.</p>
<!-- @@@resizeGL -->
<!-- $$$resizeOverlayGL[overload1]$$$resizeOverlayGLintint -->
<h3 class="fn" id="resizeOverlayGL"><a name="resizeOverlayGL"></a><code>[virtual protected] </code><span class="type">void</span> QGLWidget::<span class="name">resizeOverlayGL</span>(<span class="type">int</span> <i>width</i>, <span class="type">int</span> <i>height</i>)</h3>
<p>This virtual function is used in the same manner as <a href="qglwidget.html#paintGL">paintGL</a>() except that it operates on the widget's overlay context instead of the widget's main context. This means that resizeOverlayGL() is called whenever the widget has been resized. The new size is passed in <i>width</i> and <i>height</i>. Reimplement it in a subclass.</p>
<p>There is no need to call <a href="qglwidget.html#makeOverlayCurrent">makeOverlayCurrent</a>() because this has already been done when this function is called.</p>
<!-- @@@resizeOverlayGL -->
<!-- $$$setAutoBufferSwap[overload1]$$$setAutoBufferSwapbool -->
<h3 class="fn" id="setAutoBufferSwap"><a name="setAutoBufferSwap"></a><code>[protected] </code><span class="type">void</span> QGLWidget::<span class="name">setAutoBufferSwap</span>(<span class="type">bool</span> <i>on</i>)</h3>
<p>If <i>on</i> is true automatic GL buffer swapping is switched on; otherwise it is switched off.</p>
<p>If <i>on</i> is true and the widget is using a double-buffered format, the background and foreground GL buffers will automatically be swapped after each <a href="qglwidget.html#paintGL">paintGL</a>() call.</p>
<p>The buffer auto-swapping is on by default.</p>
<p><b>See also </b><a href="qglwidget.html#autoBufferSwap">autoBufferSwap</a>(), <a href="qglwidget.html#doubleBuffer">doubleBuffer</a>(), and <a href="qglwidget.html#swapBuffers">swapBuffers</a>().</p>
<!-- @@@setAutoBufferSwap -->
<!-- $$$setColormap[overload1]$$$setColormapconstQGLColormap& -->
<h3 class="fn" id="setColormap"><a name="setColormap"></a><span class="type">void</span> QGLWidget::<span class="name">setColormap</span>(const <span class="type"><a href="qglcolormap.html">QGLColormap</a></span> &amp;<i>cmap</i>)</h3>
<p>Set the colormap for this widget to <i>cmap</i>. Usually it is only top-level widgets that can have colormaps installed.</p>
<p><b>See also </b><a href="qglwidget.html#colormap">colormap</a>().</p>
<!-- @@@setColormap -->
<!-- $$$swapBuffers[overload1]$$$swapBuffers -->
<h3 class="fn" id="swapBuffers"><a name="swapBuffers"></a><span class="type">void</span> QGLWidget::<span class="name">swapBuffers</span>()</h3>
<p>Swaps the screen contents with an off-screen buffer. This only works if the widget's format specifies double buffer mode.</p>
<p>Normally, there is no need to explicitly call this function because it is done automatically after each widget repaint, i.e&#x2e; each time after <a href="qglwidget.html#paintGL">paintGL</a>() has been executed.</p>
<p><b>See also </b><a href="qglwidget.html#doubleBuffer">doubleBuffer</a>(), <a href="qglwidget.html#setAutoBufferSwap">setAutoBufferSwap</a>(), and <a href="qglformat.html#setDoubleBuffer">QGLFormat::setDoubleBuffer</a>().</p>
<!-- @@@swapBuffers -->
<!-- $$$updateGL[overload1]$$$updateGL -->
<h3 class="fn" id="updateGL"><a name="updateGL"></a><code>[virtual slot] </code><span class="type">void</span> QGLWidget::<span class="name">updateGL</span>()</h3>
<p>Updates the widget by calling <a href="qglwidget.html#glDraw">glDraw</a>().</p>
<!-- @@@updateGL -->
<!-- $$$updateOverlayGL[overload1]$$$updateOverlayGL -->
<h3 class="fn" id="updateOverlayGL"><a name="updateOverlayGL"></a><code>[virtual slot] </code><span class="type">void</span> QGLWidget::<span class="name">updateOverlayGL</span>()</h3>
<p>Updates the widget's overlay (if any). Will cause the virtual function <a href="qglwidget.html#paintOverlayGL">paintOverlayGL</a>() to be executed.</p>
<p>The widget's rendering context will become the current context and <a href="qglwidget.html#initializeGL">initializeGL</a>() will be called if it hasn't already been called.</p>
<!-- @@@updateOverlayGL -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>