Qt 4.8
Public Functions | Friends | List of all members
QGLWidget Class Reference

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

#include <qgl.h>

Inheritance diagram for QGLWidget:
QWidget QObject QPaintDevice QGLOverlayWidget

Public Functions

void setContext (QGLContext *context, const QGLContext *shareContext=0, bool deleteOldContext=true)
 Sets a new QGLContext, context, for this QGLWidget, using the shared context, shareContext. More...
 
- Public Functions inherited from QWidget
bool acceptDrops () const
 
QString accessibleDescription () const
 
QString accessibleName () const
 
QList< QAction * > actions () const
 Returns the (possibly empty) list of this widget's actions. More...
 
void activateWindow ()
 Sets the top-level widget containing this widget to be the active window. More...
 
void addAction (QAction *action)
 Appends the action action to this widget's list of actions. More...
 
void addActions (QList< QAction *> actions)
 Appends the actions actions to this widget's list of actions. More...
 
void adjustSize ()
 Adjusts the size of the widget to fit its contents. More...
 
bool autoFillBackground () const
 
QPalette::ColorRole backgroundRole () const
 Returns the background role of the widget. More...
 
QSize baseSize () const
 
QWidgetchildAt (int x, int y) const
 Returns the visible child widget at the position ({x}, {y}) in the widget's coordinate system. More...
 
QWidgetchildAt (const QPoint &p) const
 Returns the visible child widget at point p in the widget's own coordinate system. More...
 
QRect childrenRect () const
 
QRegion childrenRegion () const
 
void clearFocus ()
 Takes keyboard input focus from the widget. More...
 
void clearMask ()
 Removes any mask set by setMask(). More...
 
QMargins contentsMargins () const
 The contentsMargins function returns the widget's contents margins. More...
 
QRect contentsRect () const
 Returns the area inside the widget's margins. More...
 
Qt::ContextMenuPolicy contextMenuPolicy () const
 
void createWinId ()
 
QCursor cursor () const
 
int devType () const
 
WId effectiveWinId () const
 Returns the effective window system identifier of the widget, i. More...
 
void ensurePolished () const
 Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette). More...
 
Qt::FocusPolicy focusPolicy () const
 
QWidgetfocusProxy () const
 Returns the focus proxy, or 0 if there is no focus proxy. More...
 
QWidgetfocusWidget () const
 Returns the last child of this widget that setFocus had been called on. More...
 
const QFontfont () const
 
QFontInfo fontInfo () const
 Returns the font info for the widget's current font. More...
 
QFontMetrics fontMetrics () const
 Returns the font metrics for the widget's current font. More...
 
QPalette::ColorRole foregroundRole () const
 Returns the foreground role. More...
 
QRect frameGeometry () const
 
QSize frameSize () const
 
const QRectgeometry () const
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 Returns the widget's contents margins for left, top, right, and bottom. More...
 
HDC getDC () const
 Returns the window system handle of the widget, for low-level access. More...
 
void grabGesture (Qt::GestureType type, Qt::GestureFlags flags=Qt::GestureFlags())
 Subscribes the widget to a given gesture with specific flags. More...
 
void grabKeyboard ()
 Grabs the keyboard input. More...
 
void grabMouse ()
 Grabs the mouse input. More...
 
void grabMouse (const QCursor &)
 
int grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
 Adds a shortcut to Qt's shortcut system that watches for the given key sequence in the given context. More...
 
QGraphicsEffectgraphicsEffect () const
 The graphicsEffect function returns a pointer to the widget's graphics effect. More...
 
QGraphicsProxyWidgetgraphicsProxyWidget () const
 Returns the proxy widget for the corresponding embedded widget in a graphics view; otherwise returns 0. More...
 
bool hasFocus () const
 
bool hasMouseTracking () const
 
int height () const
 
virtual int heightForWidth (int) const
 Returns the preferred height for this widget, given the width w. More...
 
QInputContextinputContext ()
 This function returns the QInputContext for this widget. More...
 
Qt::InputMethodHints inputMethodHints () const
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery) const
 This method is only relevant for input widgets. More...
 
void insertAction (QAction *before, QAction *action)
 Inserts the action action to this widget's list of actions, before the action before. More...
 
void insertActions (QAction *before, QList< QAction *> actions)
 Inserts the actions actions to this widget's list of actions, before the action before. More...
 
WId internalWinId () const
 Returns the window system identifier of the widget, or 0 if the widget is not created yet. More...
 
bool isActiveWindow () const
 
bool isAncestorOf (const QWidget *child) const
 Returns true if this widget is a parent, (or grandparent and so on to any level), of the given child, and both widgets are within the same window; otherwise returns false. More...
 
bool isEnabled () const
 
bool isEnabledTo (QWidget *) const
 Returns true if this widget would become enabled if ancestor is enabled; otherwise returns false. More...
 
bool isEnabledToTLW () const
 This function is deprecated. More...
 
bool isFullScreen () const
 
bool isHidden () const
 Returns true if the widget is hidden, otherwise returns false. More...
 
bool isLeftToRight () const
 
bool isMaximized () const
 
bool isMinimized () const
 
bool isModal () const
 
bool isRightToLeft () const
 
bool isTopLevel () const
 Use isWindow() instead. More...
 
bool isVisible () const
 
bool isVisibleTo (QWidget *) const
 Returns true if this widget would become visible if ancestor is shown; otherwise returns false. More...
 
bool isWindow () const
 Returns true if the widget is an independent window, otherwise returns false. More...
 
bool isWindowModified () const
 
QLayoutlayout () const
 Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed. More...
 
Qt::LayoutDirection layoutDirection () const
 
QLocale locale () const
 
Qt::HANDLE macCGHandle () const
 Returns the CoreGraphics handle of the widget. More...
 
Qt::HANDLE macQDHandle () const
 Returns the QuickDraw handle of the widget. More...
 
QPoint mapFrom (QWidget *, const QPoint &) const
 Translates the widget coordinate pos from the coordinate system of parent to this widget's coordinate system. More...
 
QPoint mapFromGlobal (const QPoint &) const
 Translates the global screen coordinate pos to widget coordinates. More...
 
QPoint mapFromParent (const QPoint &) const
 Translates the parent widget coordinate pos to widget coordinates. More...
 
QPoint mapTo (QWidget *, const QPoint &) const
 Translates the widget coordinate pos to the coordinate system of parent. More...
 
QPoint mapToGlobal (const QPoint &) const
 Translates the widget coordinate pos to global screen coordinates. More...
 
QPoint mapToParent (const QPoint &) const
 Translates the widget coordinate pos to a coordinate in the parent widget. More...
 
QRegion mask () const
 Returns the mask currently set on a widget. More...
 
int maximumHeight () const
 
QSize maximumSize () const
 
int maximumWidth () const
 
int minimumHeight () const
 
QSize minimumSize () const
 
virtual QSize minimumSizeHint () const
 
int minimumWidth () const
 
void move (int x, int y)
 This corresponds to move(QPoint(x, y)). More...
 
void move (const QPoint &)
 
QWidgetnativeParentWidget () const
 Returns the native parent for this widget, i. More...
 
QWidgetnextInFocusChain () const
 Returns the next widget in this widget's focus chain. More...
 
QRect normalGeometry () const
 
void overrideWindowFlags (Qt::WindowFlags type)
 Sets the window flags for the widget to flags, without telling the window system. More...
 
void overrideWindowState (Qt::WindowStates state)
 
const QPalettepalette () const
 
QWidgetparentWidget () const
 Returns the parent of this widget, or 0 if it does not have any parent widget. More...
 
QPoint pos () const
 
QWidgetpreviousInFocusChain () const
 The previousInFocusChain function returns the previous widget in this widget's focus chain. More...
 
 QWidget (QWidget *parent=0, Qt::WindowFlags f=0)
 Constructs a widget which is a child of parent, with widget flags set to f. More...
 
QRect rect () const
 
void releaseDC (HDC) const
 Releases the HDC hdc acquired by a previous call to getDC(). More...
 
void releaseKeyboard ()
 Releases the keyboard grab. More...
 
void releaseMouse ()
 Releases the mouse grab. More...
 
void releaseShortcut (int id)
 Removes the shortcut with the given id from Qt's shortcut system. More...
 
void removeAction (QAction *action)
 Removes the action action from this widget's list of actions. More...
 
void render (QPaintDevice *target, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
 Renders the sourceRegion of this widget into the target using renderFlags to determine how to render. More...
 
void render (QPainter *painter, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
 Renders the widget into the painter's QPainter::device(). More...
 
void repaint (int x, int y, int w, int h)
 This version repaints a rectangle (x, y, w, h) inside the widget. More...
 
void repaint (const QRect &)
 This version repaints a rectangle rect inside the widget. More...
 
void repaint (const QRegion &)
 This version repaints a region rgn inside the widget. More...
 
void resize (int w, int h)
 This corresponds to resize(QSize(w, h)). More...
 
void resize (const QSize &)
 
bool restoreGeometry (const QByteArray &geometry)
 Restores the geometry and state top-level widgets stored in the byte array geometry. More...
 
QByteArray saveGeometry () const
 Saves the current geometry and state for top-level widgets. More...
 
void scroll (int dx, int dy)
 Scrolls the widget including its children dx pixels to the right and dy downward. More...
 
void scroll (int dx, int dy, const QRect &)
 This version only scrolls r and does not move the children of the widget. More...
 
void setAcceptDrops (bool on)
 
void setAccessibleDescription (const QString &description)
 
void setAccessibleName (const QString &name)
 
void setAttribute (Qt::WidgetAttribute, bool on=true)
 Sets the attribute attribute on this widget if on is true; otherwise clears the attribute. More...
 
void setAutoFillBackground (bool enabled)
 
void setBackgroundRole (QPalette::ColorRole)
 Sets the background role of the widget to role. More...
 
void setBaseSize (const QSize &)
 
void setBaseSize (int basew, int baseh)
 This corresponds to setBaseSize(QSize(basew, baseh)). More...
 
void setContentsMargins (int left, int top, int right, int bottom)
 Sets the margins around the contents of the widget to have the sizes left, top, right, and bottom. More...
 
void setContentsMargins (const QMargins &margins)
 The setContentsMargins function sets the margins around the widget's contents. More...
 
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
 
void setCursor (const QCursor &)
 
void setFixedHeight (int h)
 Sets both the minimum and maximum heights of the widget to h without changing the widths. More...
 
void setFixedSize (const QSize &)
 Sets both the minimum and maximum sizes of the widget to s, thereby preventing it from ever growing or shrinking. More...
 
void setFixedSize (int w, int h)
 Sets the width of the widget to w and the height to h. More...
 
void setFixedWidth (int w)
 Sets both the minimum and maximum width of the widget to w without changing the heights. More...
 
void setFocus (Qt::FocusReason reason)
 Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the active window. More...
 
void setFocusPolicy (Qt::FocusPolicy policy)
 
void setFocusProxy (QWidget *)
 Sets the widget's focus proxy to widget w. More...
 
void setFont (const QFont &)
 Use the single-argument overload instead. More...
 
void setForegroundRole (QPalette::ColorRole)
 Sets the foreground role of the widget to role. More...
 
void setGeometry (int x, int y, int w, int h)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This corresponds to setGeometry(QRect(x, y, w, h)). More...
 
void setGeometry (const QRect &)
 
void setGraphicsEffect (QGraphicsEffect *effect)
 The setGraphicsEffect function is for setting the widget's graphics effect. More...
 
void setInputContext (QInputContext *)
 This function sets the input context context on this widget. More...
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
void setLayout (QLayout *)
 Sets the layout manager for this widget to layout. More...
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
void setLocale (const QLocale &locale)
 
void setMask (const QBitmap &)
 Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible. More...
 
void setMask (const QRegion &)
 Causes only the parts of the widget which overlap region to be visible. More...
 
void setMaximumHeight (int maxh)
 
void setMaximumSize (const QSize &)
 
void setMaximumSize (int maxw, int maxh)
 This function corresponds to setMaximumSize(QSize(maxw, maxh)). More...
 
void setMaximumWidth (int maxw)
 
void setMinimumHeight (int minh)
 
void setMinimumSize (const QSize &)
 
void setMinimumSize (int minw, int minh)
 This function corresponds to setMinimumSize(QSize(minw, minh)). More...
 
void setMinimumWidth (int minw)
 
void setMouseTracking (bool enable)
 
void setPalette (const QPalette &)
 Use the single-argument overload instead. More...
 
void setParent (QWidget *parent)
 Sets the parent of the widget to parent, and resets the window flags. More...
 
void setParent (QWidget *parent, Qt::WindowFlags f)
 This function also takes widget flags, f as an argument. More...
 
void setShortcutAutoRepeat (int id, bool enable=true)
 If enable is true, auto repeat of the shortcut with the given id is enabled; otherwise it is disabled. More...
 
void setShortcutEnabled (int id, bool enable=true)
 If enable is true, the shortcut with the given id is enabled; otherwise the shortcut is disabled. More...
 
void setSizeIncrement (const QSize &)
 
void setSizeIncrement (int w, int h)
 Sets the x (width) size increment to w and the y (height) size increment to h. More...
 
void setSizePolicy (QSizePolicy)
 
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
 Sets the size policy of the widget to horizontal and vertical, with standard stretch and no height-for-width. More...
 
void setStatusTip (const QString &)
 
void setStyle (QStyle *)
 Sets the widget's GUI style to style. More...
 
void setToolTip (const QString &)
 
void setUpdatesEnabled (bool enable)
 
void setupUi (QWidget *widget)
 Sets up the user interface for the specified widget. More...
 
void setWhatsThis (const QString &)
 
void setWindowFilePath (const QString &filePath)
 
void setWindowFlags (Qt::WindowFlags type)
 
void setWindowIcon (const QIcon &icon)
 
void setWindowIconText (const QString &)
 
void setWindowModality (Qt::WindowModality windowModality)
 
void setWindowOpacity (qreal level)
 
void setWindowRole (const QString &)
 Sets the window's role to role. More...
 
void setWindowState (Qt::WindowStates state)
 Sets the window state to windowState. More...
 
void setWindowSurface (QWindowSurface *surface)
 Sets the window surface to be the surface specified. More...
 
QSize size () const
 
virtual QSize sizeHint () const
 
QSize sizeIncrement () const
 
QSizePolicy sizePolicy () const
 
void stackUnder (QWidget *)
 Places the widget under w in the parent widget's stack. More...
 
QString statusTip () const
 
QStylestyle () const
 
QString styleSheet () const
 
bool testAttribute (Qt::WidgetAttribute) const
 Returns true if attribute attribute is set on this widget; otherwise returns false. More...
 
QString toolTip () const
 
QWidgettopLevelWidget () const
 
bool underMouse () const
 Returns true if the widget is under the mouse cursor; otherwise returns false. More...
 
void ungrabGesture (Qt::GestureType type)
 Unsubscribes the widget from a given gesture type. More...
 
void unsetCursor ()
 
void unsetLayoutDirection ()
 
void unsetLocale ()
 
void update (int x, int y, int w, int h)
 This version updates a rectangle (x, y, w, h) inside the widget. More...
 
void update (const QRect &)
 This version updates a rectangle rect inside the widget. More...
 
void update (const QRegion &)
 This version repaints a region rgn inside the widget. More...
 
void updateGeometry ()
 Notifies the layout system that this widget has changed and may need to change geometry. More...
 
bool updatesEnabled () const
 
QRegion visibleRegion () const
 Returns the unobscured region where paint events can occur. More...
 
QString whatsThis () const
 
int width () const
 
QWidgetwindow () const
 Returns the window for this widget, i.e. More...
 
QString windowFilePath () const
 
Qt::WindowFlags windowFlags () const
 Window flags are a combination of a type (e. More...
 
QIcon windowIcon () const
 
QString windowIconText () const
 
Qt::WindowModality windowModality () const
 
qreal windowOpacity () const
 
QString windowRole () const
 Returns the window's role, or an empty string. More...
 
Qt::WindowStates windowState () const
 Returns the current window state. More...
 
QWindowSurfacewindowSurface () const
 Returns the QWindowSurface this widget will be drawn into. More...
 
QString windowTitle () const
 
Qt::WindowType windowType () const
 Returns the window type of this widget. More...
 
WId winId () const
 Returns the window system identifier of the widget. More...
 
int x () const
 
const QX11Infox11Info () const
 Returns information about the configuration of the X display used to display the widget. More...
 
Qt::HANDLE x11PictureHandle () const
 Returns the X11 Picture handle of the widget for XRender support. More...
 
int y () const
 
 ~QWidget ()
 Destroys the widget. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 
- Public Functions inherited from QPaintDevice
int colorCount () const
 
int depth () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
QT_DEPRECATED int numColors () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
int width () const
 
int widthMM () const
 
virtual ~QPaintDevice ()
 

Friends

class QGLContext
 
class QGLContextPrivate
 
class QGLDrawable
 
class QGLOverlayWidget
 
class QGLPaintDevice
 
class QGLPixelBuffer
 
class QGLPixelBufferPrivate
 
class QGLWidgetGLPaintDevice
 
class QMacGLWindowChangeEvent
 
class QOpenGLPaintEngine
 
 QGLWidget (QWidget *parent=0, const QGLWidget *shareWidget=0, Qt::WindowFlags f=0)
 Constructs an OpenGL widget with a parent widget. More...
 
 QGLWidget (QGLContext *context, QWidget *parent=0, const QGLWidget *shareWidget=0, Qt::WindowFlags f=0)
 Constructs an OpenGL widget with parent parent. More...
 
 QGLWidget (const QGLFormat &format, QWidget *parent=0, const QGLWidget *shareWidget=0, Qt::WindowFlags f=0)
 Constructs an OpenGL widget with parent parent. More...
 
 ~QGLWidget ()
 Destroys the widget. More...
 
void qglColor (const QColor &c) const
 Convenience function for specifying a drawing color to OpenGL. More...
 
void qglClearColor (const QColor &c) const
 Convenience function for specifying the clearing color to OpenGL. More...
 
bool isValid () const
 Returns true if the widget has a valid GL rendering context; otherwise returns false. More...
 
bool isSharing () const
 Returns true if this widget's GL context is shared with another GL context, otherwise false is returned. More...
 
void makeCurrent ()
 Makes this widget the current widget for OpenGL operations, i. More...
 
void doneCurrent ()
 Makes no GL context the current context. More...
 
bool doubleBuffer () const
 Returns true if the contained GL rendering context has double buffering; otherwise returns false. More...
 
void swapBuffers ()
 Swaps the screen contents with an off-screen buffer. More...
 
QGLFormat format () const
 Returns the format of the contained GL rendering context. More...
 
void setFormat (const QGLFormat &format)
 Sets a new format for this widget. More...
 
const QGLContextcontext () const
 Returns the context of this widget. More...
 
QPixmap renderPixmap (int w=0, int h=0, bool useContext=false)
 Renders the current scene on a pixmap and returns the pixmap. More...
 
QImage grabFrameBuffer (bool withAlpha=false)
 Returns an image of the frame buffer. More...
 
void makeOverlayCurrent ()
 Makes the overlay context of this widget current. More...
 
const QGLContextoverlayContext () const
 Returns the overlay context of this widget, or 0 if this widget has no overlay. More...
 
void setMouseTracking (bool enable)
 If enable is true then mouse tracking is enabled; otherwise it is disabled. More...
 
const QGLColormapcolormap () const
 Returns the colormap for this widget. More...
 
void setColormap (const QGLColormap &map)
 Set the colormap for this widget to cmap. More...
 
void renderText (int x, int y, const QString &str, const QFont &fnt=QFont(), int listBase=2000)
 Renders the string str into the GL context of this widget. More...
 
void renderText (double x, double y, double z, const QString &str, const QFont &fnt=QFont(), int listBase=2000)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.x, y and z are specified in scene or object coordinates relative to the currently set projection and model matrices. More...
 
QPaintEnginepaintEngine () const
 Returns the GL widget's paint engine. More...
 
GLuint bindTexture (const QImage &image, GLenum target, GLint format, QGLContext::BindOptions options)
 The binding options are a set of options used to decide how to bind the texture to the context. More...
 
GLuint bindTexture (const QPixmap &pixmap, GLenum target, GLint format, QGLContext::BindOptions options)
 Generates and binds a 2D GL texture to the current context, based on pixmap. More...
 
GLuint bindTexture (const QImage &image, GLenum target=GL_TEXTURE_2D, GLint format=GL_RGBA)
 Calls QGLContext:::bindTexture(image, target, format) on the currently set context. More...
 
GLuint bindTexture (const QPixmap &pixmap, GLenum target=GL_TEXTURE_2D, GLint format=GL_RGBA)
 Calls QGLContext:::bindTexture(pixmap, target, format) on the currently set context. More...
 
GLuint bindTexture (const QString &fileName)
 Calls QGLContext::bindTexture(fileName) on the currently set context. More...
 
void deleteTexture (GLuint tx_id)
 Calls QGLContext::deleteTexture(id) on the currently set context. More...
 
void drawTexture (const QRectF &target, GLuint textureId, GLenum textureTarget=GL_TEXTURE_2D)
 Calls the corresponding QGLContext::drawTexture() with target, textureId, and textureTarget for this widget's context. More...
 
void drawTexture (const QPointF &point, GLuint textureId, GLenum textureTarget=GL_TEXTURE_2D)
 Calls the corresponding QGLContext::drawTexture() with point, textureId, and textureTarget for this widget's context. More...
 
static QImage convertToGLFormat (const QImage &img)
 Converts the image img into the unnamed format expected by OpenGL functions such as glTexImage2D(). More...
 
virtual void updateGL ()
 Updates the widget by calling glDraw(). More...
 
virtual void updateOverlayGL ()
 Updates the widget's overlay (if any). More...
 
bool event (QEvent *)
 Reimplemented Function More...
 
virtual void initializeGL ()
 This virtual function is called once before the first call to paintGL() or resizeGL(), and then once whenever the widget has been assigned a new QGLContext. More...
 
virtual void resizeGL (int w, int h)
 This virtual function is called whenever the widget has been resized. More...
 
virtual void paintGL ()
 This virtual function is called whenever the widget needs to be painted. More...
 
virtual void initializeOverlayGL ()
 This virtual function is used in the same manner as initializeGL() except that it operates on the widget's overlay context instead of the widget's main context. More...
 
virtual void resizeOverlayGL (int w, int h)
 This virtual function is used in the same manner as paintGL() except that it operates on the widget's overlay context instead of the widget's main context. More...
 
virtual void paintOverlayGL ()
 This virtual function is used in the same manner as paintGL() except that it operates on the widget's overlay context instead of the widget's main context. More...
 
void setAutoBufferSwap (bool on)
 If on is true automatic GL buffer swapping is switched on; otherwise it is switched off. More...
 
bool autoBufferSwap () const
 Returns true if the widget is doing automatic GL buffer swapping; otherwise returns false. More...
 
void paintEvent (QPaintEvent *)
 Handles paint events passed in the event parameter. More...
 
void resizeEvent (QResizeEvent *)
 Handles resize events that are passed in the event parameter. More...
 
virtual void glInit ()
 Initializes OpenGL for this widget's context. More...
 
virtual void glDraw ()
 Executes the virtual function paintGL(). More...
 
int fontDisplayListBase (const QFont &fnt, int listBase=2000)
 Returns the value of the first display list that is generated for the characters in the given font. More...
 

Additional Inherited Members

- Public Types inherited from QWidget
enum  RenderFlag { DrawWindowBackground = 0x1, DrawChildren = 0x2, IgnoreMask = 0x4 }
 This enum describes how to render the widget when calling QWidget::render(). More...
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric {
  PdmWidth = 1, PdmHeight, PdmWidthMM, PdmHeightMM,
  PdmNumColors, PdmDepth, PdmDpiX, PdmDpiY,
  PdmPhysicalDpiX, PdmPhysicalDpiY
}
 
- Public Slots inherited from QWidget
bool close ()
 Closes this widget. More...
 
void hide ()
 Hides the widget. More...
 
void lower ()
 Lowers the widget to the bottom of the parent widget's stack. More...
 
void raise ()
 Raises this widget to the top of the parent widget's stack. More...
 
void repaint ()
 Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the widget is hidden. More...
 
void setDisabled (bool)
 Disables widget input events if disable is true; otherwise enables input events. More...
 
void setEnabled (bool)
 
void setFocus ()
 Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the active window. More...
 
void setHidden (bool hidden)
 Convenience function, equivalent to setVisible(!hidden). More...
 
QT_MOC_COMPAT void setShown (bool shown)
 Use setVisible(shown) instead. More...
 
void setStyleSheet (const QString &styleSheet)
 
virtual void setVisible (bool visible)
 
void setWindowModified (bool)
 
void setWindowTitle (const QString &)
 
void show ()
 Shows the widget and its child widgets. More...
 
void showFullScreen ()
 Shows the widget in full-screen mode. More...
 
void showMaximized ()
 Shows the widget maximized. More...
 
void showMinimized ()
 Shows the widget minimized, as an icon. More...
 
void showNormal ()
 Restores the widget after it has been maximized or minimized. More...
 
void update ()
 Updates the widget unless updates are disabled or the widget is hidden. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QWidget
void customContextMenuRequested (const QPoint &pos)
 This signal is emitted when the widget's contextMenuPolicy is Qt::CustomContextMenu, and the user has requested a context menu on the widget. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QWidget
static QWidgetfind (WId)
 Returns a pointer to the widget with window identifer/handle id. More...
 
static QWidgetkeyboardGrabber ()
 Returns the widget that is currently grabbing the keyboard input. More...
 
static QWidgetmouseGrabber ()
 Returns the widget that is currently grabbing the mouse input. More...
 
static void setTabOrder (QWidget *, QWidget *)
 Puts the second widget after the first widget in the focus order. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Functions inherited from QPaintDevice
static QWSDisplayqwsDisplay ()
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Slots inherited from QWidget
void updateMicroFocus ()
 Updates the widget's micro focus. More...
 
- Protected Functions inherited from QWidget
virtual void actionEvent (QActionEvent *)
 This event handler is called with the given event whenever the widget's actions are changed. More...
 
virtual void changeEvent (QEvent *)
 This event handler can be reimplemented to handle state changes. More...
 
virtual void closeEvent (QCloseEvent *)
 This event handler is called with the given event when Qt receives a window close request for a top-level widget from the window system. More...
 
virtual void contextMenuEvent (QContextMenuEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive widget context menu events. More...
 
void create (WId=0, bool initializeWindow=true, bool destroyOldWindow=true)
 Creates a new widget window if window is 0, otherwise sets the widget's window to window. More...
 
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
 Frees up window system resources. More...
 
virtual void dragEnterEvent (QDragEnterEvent *)
 This event handler is called when a drag is in progress and the mouse enters this widget. More...
 
virtual void dragLeaveEvent (QDragLeaveEvent *)
 This event handler is called when a drag is in progress and the mouse leaves this widget. More...
 
virtual void dragMoveEvent (QDragMoveEvent *)
 This event handler is called if a drag is in progress, and when any of the following conditions occur: the cursor enters this widget, the cursor moves within this widget, or a modifier key is pressed on the keyboard while this widget has the focus. More...
 
virtual void dropEvent (QDropEvent *)
 This event handler is called when the drag is dropped on this widget. More...
 
virtual void enabledChange (bool)
 
virtual void enterEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive widget enter events which are passed in the event parameter. More...
 
virtual void focusInEvent (QFocusEvent *)
 This event handler can be reimplemented in a subclass to receive keyboard focus events (focus received) for the widget. More...
 
bool focusNextChild ()
 Finds a new widget to give the keyboard focus to, as appropriate for Tab, and returns true if it can find a new widget, or false if it can't. More...
 
virtual bool focusNextPrevChild (bool next)
 Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it can't. More...
 
virtual void focusOutEvent (QFocusEvent *)
 This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) for the widget. More...
 
bool focusPreviousChild ()
 Finds a new widget to give the keyboard focus to, as appropriate for Shift+Tab, and returns true if it can find a new widget, or false if it can't. More...
 
virtual void fontChange (const QFont &)
 
virtual void hideEvent (QHideEvent *)
 This event handler can be reimplemented in a subclass to receive widget hide events. More...
 
virtual void inputMethodEvent (QInputMethodEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive Input Method composition events. More...
 
virtual void keyPressEvent (QKeyEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive key press events for the widget. More...
 
virtual void keyReleaseEvent (QKeyEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive key release events for the widget. More...
 
virtual void languageChange ()
 
virtual void leaveEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive widget leave events which are passed in the event parameter. More...
 
virtual bool macEvent (EventHandlerCallRef, EventRef)
 This special event handler can be reimplemented in a subclass to receive native Macintosh events. More...
 
int metric (PaintDeviceMetric) const
 Internal implementation of the virtual QPaintDevice::metric() function. More...
 
virtual void mouseDoubleClickEvent (QMouseEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse double click events for the widget. More...
 
virtual void mouseMoveEvent (QMouseEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse move events for the widget. More...
 
virtual void mousePressEvent (QMouseEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse press events for the widget. More...
 
virtual void mouseReleaseEvent (QMouseEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse release events for the widget. More...
 
virtual void moveEvent (QMoveEvent *)
 This event handler can be reimplemented in a subclass to receive widget move events which are passed in the event parameter. More...
 
virtual void paletteChange (const QPalette &)
 
 QWidget (QWidgetPrivate &d, QWidget *parent, Qt::WindowFlags f)
 
virtual bool qwsEvent (QWSEvent *)
 This special event handler can be reimplemented in a subclass to receive native Qt for Embedded Linux events which are passed in the event parameter. More...
 
void resetInputContext ()
 This function can be called on the widget that currently has focus to reset the input method operating on it. More...
 
virtual void showEvent (QShowEvent *)
 This event handler can be reimplemented in a subclass to receive widget show events which are passed in the event parameter. More...
 
virtual void styleChange (QStyle &)
 
virtual void tabletEvent (QTabletEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive tablet events for the widget. More...
 
virtual void wheelEvent (QWheelEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive wheel events for the widget. More...
 
virtual void windowActivationChange (bool)
 
virtual bool winEvent (MSG *message, long *result)
 This special event handler can be reimplemented in a subclass to receive native Windows events which are passed in the message parameter. More...
 
virtual bool x11Event (XEvent *)
 This special event handler can be reimplemented in a subclass to receive native X11 events passed in the event parameter. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Functions inherited from QPaintDevice
 QPaintDevice ()
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Protected Variables inherited from QPaintDevice
ushort painters
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

The QGLWidget class is a widget for rendering OpenGL graphics.

QGLWidget 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 QWidget, except that you have the choice between using QPainter and standard OpenGL rendering commands.

QGLWidget provides three convenient virtual functions that you can reimplement in your subclass to perform the typical OpenGL tasks:

Here is a rough outline of how a QGLWidget subclass might look:

class MyGLDrawer : public QGLWidget
{
Q_OBJECT // must include this if you use Qt signals/slots
public:
MyGLDrawer(QWidget *parent)
: QGLWidget(parent) {}
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();
...
}
};

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

Your widget's OpenGL rendering context is made current when paintGL(), resizeGL(), or initializeGL() is called. If you need to call the standard OpenGL API functions from other places (e.g. in your widget's constructor or in your own paint functions), you must call makeCurrent() first.

QGLWidget provides functions for requesting a new display format and you can also create widgets with customized rendering contexts.

You can also share OpenGL display lists between QGLWidget objects (see the documentation of the QGLWidget constructors for details).

Note that under Windows, the QGLContext belonging to a QGLWidget has to be recreated when the QGLWidget 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 QGLContext on a QGLWidget. It is possible to work around this issue by putting the QGLWidget inside a dummy widget and then reparenting the dummy widget, instead of the QGLWidget. This will side-step the issue altogether, and is what we recommend for users that need this kind of functionality.

On Mac OS X, when Qt is built with Cocoa support, a QGLWidget 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.

Overlays

The QGLWidget creates a GL overlay context in addition to the normal context if overlays are supported by the underlying system.

If you want to use overlays, you specify it in the format. (Note: Overlay must be requested in the format passed to the QGLWidget constructor.) Your GL widget should also implement some or all of these virtual methods:

These methods work in the same way as the normal paintGL() 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 makeOverlayCurrent(), and you can access the overlay context directly (e.g. to ask for its transparent color) by calling overlayContext().

On X servers in which the default visual is in an overlay plane, non-GL Qt windows can also be used for overlays.

Painting Techniques

As described above, subclass QGLWidget to render pure 3D content in the following way:

It is also possible to draw 2D graphics onto a QGLWidget subclass, it is necessary to reimplement QGLWidget::paintEvent() and do the following:

Overpainting 2D content on top of 3D content takes a little more effort. One approach to doing this is shown in the Overpainting Example{Overpainting} example.

Threading

As of Qt version 4.8, support for doing threaded GL rendering has been improved. There are three scenarios that we currently support:

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 QPainter on a QGLWidget and the widget's rendering context is current in another thread, it will fail.

Note that under X11 it is necessary to set the Qt::AA_X11InitThreads application attribute to make the X11 library and GLX calls thread safe, otherwise the above scenarios will fail.

In addition to this, rendering using raw GL calls in a separate thread is supported.

OpenGL is a trademark of Silicon Graphics, Inc. in the United States and other countries.

See also
QGLPixelBuffer, {Hello GL Example}, {2D Painting Example}, {Overpainting Example}, {Grabber Example}

Definition at line 474 of file qgl.h.

Constructors and Destructors

◆ QGLWidget() [1/3]

QGLWidget::QGLWidget ( QWidget parent = 0,
const QGLWidget shareWidget = 0,
Qt::WindowFlags  f = 0 
)
explicit

Constructs an OpenGL widget with a parent widget.

The default format is used. The widget will be invalid if the system has no OpenGL support.

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

If shareWidget is a valid QGLWidget, this widget will share OpenGL display lists and texture objects with shareWidget. But if shareWidget and this widget have different format() {formats}, sharing might not be possible. You can check whether sharing is in effect by calling isSharing().

The initialization of OpenGL rendering state, etc. should be done by overriding the initializeGL() function, rather than in the constructor of your QGLWidget subclass.

See also
QGLFormat::defaultFormat(), {Textures Example}

Definition at line 3962 of file qgl.cpp.

3963  : QWidget(*(new QGLWidgetPrivate), parent, f | Qt::MSWindowsOwnDC)
3964 {
3965  Q_D(QGLWidget);
3968  setAutoFillBackground(true); // for compatibility
3969  d->init(new QGLContext(QGLFormat::defaultFormat(), this), shareWidget);
3970 }
double d
Definition: qnumeric_p.h:62
friend class QGLContext
Definition: qgl.h:600
#define Q_D(Class)
Definition: qglobal.h:2482
QWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a widget which is a child of parent, with widget flags set to f.
Definition: qwidget.cpp:1189
void setAutoFillBackground(bool enabled)
Definition: qwidget.cpp:631
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474
static QGLFormat defaultFormat()
Definition: qgl.cpp:1518
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087

◆ QGLWidget() [2/3]

QGLWidget::QGLWidget ( QGLContext context,
QWidget parent = 0,
const QGLWidget shareWidget = 0,
Qt::WindowFlags  f = 0 
)
explicit

Constructs an OpenGL widget with parent parent.

The context 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.

The widget will be invalid if the system has no OpenGL support.

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

If shareWidget is a valid QGLWidget, this widget will share OpenGL display lists and texture objects with shareWidget. But if shareWidget and this widget have different format() {formats}, sharing might not be possible. You can check whether sharing is in effect by calling isSharing().

The initialization of OpenGL rendering state, etc. should be done by overriding the initializeGL() function, rather than in the constructor of your QGLWidget subclass.

See also
QGLFormat::defaultFormat(), isValid()

Definition at line 4037 of file qgl.cpp.

4039  : QWidget(*(new QGLWidgetPrivate), parent, f | Qt::MSWindowsOwnDC)
4040 {
4041  Q_D(QGLWidget);
4044  setAutoFillBackground(true); // for compatibility
4045  d->init(context, shareWidget);
4046 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a widget which is a child of parent, with widget flags set to f.
Definition: qwidget.cpp:1189
void setAutoFillBackground(bool enabled)
Definition: qwidget.cpp:631
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087

◆ QGLWidget() [3/3]

QGLWidget::QGLWidget ( const QGLFormat format,
QWidget parent = 0,
const QGLWidget shareWidget = 0,
Qt::WindowFlags  f = 0 
)
explicit

Constructs an OpenGL widget with parent parent.

The format argument specifies the desired rendering options . If the underlying OpenGL/Window system cannot satisfy all the features requested in format, the nearest subset of features will be used. After creation, the format() method will return the actual format obtained.

The widget will be invalid if the system has no OpenGL support.

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

If shareWidget is a valid QGLWidget, this widget will share OpenGL display lists and texture objects with shareWidget. But if shareWidget and this widget have different format() {formats}, sharing might not be possible. You can check whether sharing is in effect by calling isSharing().

The initialization of OpenGL rendering state, etc. should be done by overriding the initializeGL() function, rather than in the constructor of your QGLWidget subclass.

See also
QGLFormat::defaultFormat(), isValid()

Definition at line 4001 of file qgl.cpp.

4003  : QWidget(*(new QGLWidgetPrivate), parent, f | Qt::MSWindowsOwnDC)
4004 {
4005  Q_D(QGLWidget);
4008  setAutoFillBackground(true); // for compatibility
4009  d->init(new QGLContext(format, this), shareWidget);
4010 }
double d
Definition: qnumeric_p.h:62
friend class QGLContext
Definition: qgl.h:600
#define Q_D(Class)
Definition: qglobal.h:2482
QWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a widget which is a child of parent, with widget flags set to f.
Definition: qwidget.cpp:1189
void setAutoFillBackground(bool enabled)
Definition: qwidget.cpp:631
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087

◆ ~QGLWidget()

QGLWidget::~QGLWidget ( )

Destroys the widget.

Definition at line 4052 of file qgl.cpp.

4053 {
4054  Q_D(QGLWidget);
4055 #if defined(GLX_MESA_release_buffers) && defined(QGL_USE_MESA_EXT)
4056  bool doRelease = (glcx && glcx->windowCreated());
4057 #endif
4058  delete d->glcx;
4059  d->glcx = 0;
4060 #if defined(Q_WS_WIN)
4061  delete d->olcx;
4062  d->olcx = 0;
4063 #endif
4064 #if defined(GLX_MESA_release_buffers) && defined(QGL_USE_MESA_EXT)
4065  if (doRelease)
4066  glXReleaseBuffersMESA(x11Display(), winId());
4067 #endif
4068  d->cleanupColormaps();
4069 
4070 #ifdef Q_WS_MAC
4071  QWidget *current = parentWidget();
4072  while (current) {
4073  qt_widget_private(current)->glWidgets.removeAll(QWidgetPrivate::GlWidgetInfo(this));
4074  if (current->isWindow())
4075  break;
4076  current = current->parentWidget();
4077  };
4078 #endif
4079 }
double d
Definition: qnumeric_p.h:62
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474
friend Q_GUI_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
Definition: qwidget.cpp:12920
WId winId() const
Returns the window system identifier of the widget.
Definition: qwidget.cpp:2557

Functions

◆ autoBufferSwap()

bool QGLWidget::autoBufferSwap ( ) const
protected

Returns true if the widget is doing automatic GL buffer swapping; otherwise returns false.

See also
setAutoBufferSwap()

Definition at line 5321 of file qgl.cpp.

5322 {
5323  Q_D(const QGLWidget);
5324  return d->autoSwap;
5325 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474

◆ bindTexture() [1/5]

GLuint QGLWidget::bindTexture ( const QImage image,
GLenum  target,
GLint  format,
QGLContext::BindOptions  options 
)

The binding options are a set of options used to decide how to bind the texture to the context.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.6

Definition at line 5352 of file qgl.cpp.

5353 {
5354  if (image.isNull())
5355  return 0;
5356 
5357  Q_D(QGLWidget);
5358  return d->glcx->bindTexture(image, target, format, options);
5359 }
double d
Definition: qnumeric_p.h:62
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474

◆ bindTexture() [2/5]

GLuint QGLWidget::bindTexture ( const QPixmap pixmap,
GLenum  target,
GLint  format,
QGLContext::BindOptions  options 
)

Generates and binds a 2D GL texture to the current context, based on pixmap.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.6

The generated texture id is returned and can be used in

The binding options are a set of options used to decide how to bind the texture to the context.

Definition at line 5412 of file qgl.cpp.

5414 {
5415  Q_D(QGLWidget);
5416  return d->glcx->bindTexture(pixmap, target, format, options);
5417 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474

◆ bindTexture() [3/5]

GLuint QGLWidget::bindTexture ( const QImage image,
GLenum  target = GL_TEXTURE_2D,
GLint  format = GL_RGBA 
)

Calls QGLContext:::bindTexture(image, target, format) on the currently set context.

See also
deleteTexture()

Definition at line 5333 of file qgl.cpp.

5334 {
5335  if (image.isNull())
5336  return 0;
5337 
5338  Q_D(QGLWidget);
5339  return d->glcx->bindTexture(image, target, format, QGLContext::DefaultBindOption);
5340 }
double d
Definition: qnumeric_p.h:62
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474

◆ bindTexture() [4/5]

GLuint QGLWidget::bindTexture ( const QPixmap pixmap,
GLenum  target = GL_TEXTURE_2D,
GLint  format = GL_RGBA 
)

Calls QGLContext:::bindTexture(pixmap, target, format) on the currently set context.

See also
deleteTexture()

Definition at line 5390 of file qgl.cpp.

5391 {
5392  if (pixmap.isNull())
5393  return 0;
5394 
5395  Q_D(QGLWidget);
5396  return d->glcx->bindTexture(pixmap, target, format, QGLContext::DefaultBindOption);
5397 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615

◆ bindTexture() [5/5]

GLuint QGLWidget::bindTexture ( const QString fileName)

Calls QGLContext::bindTexture(fileName) on the currently set context.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

See also
deleteTexture()

Definition at line 5445 of file qgl.cpp.

5446 {
5447  Q_D(QGLWidget);
5448  return d->glcx->bindTexture(fileName);
5449 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474

◆ colormap()

const QGLColormap & QGLWidget::colormap ( ) const

Returns the colormap for this widget.

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.

If no colormap has been set for this widget, the QGLColormap returned will be empty.

See also
setColormap(), QGLColormap::isEmpty()

Definition at line 974 of file qgl_mac.mm.

Referenced by event(), QGLOverlayWidget::paintGL(), qStoreColors(), qt_egl_create_surface(), and QGLWidgetPrivate::updateColormap().

975 {
976  return d_func()->cmap;
977 }

◆ context()

const QGLContext * QGLWidget::context ( ) const

Returns the context of this widget.

It is possible that the context is not valid (see isValid()), for example, if the underlying hardware does not support the format attributes that were requested.

Definition at line 5303 of file qgl.cpp.

Referenced by QMeeGoGraphicsSystem::createWindowSurface(), QGLOverlayWidget::initializeGL(), nearest_gl_texture_size(), QGLOverlayWidget::paintGL(), and qt_gl_share_context().

5304 {
5305  Q_D(const QGLWidget);
5306  return d->glcx;
5307 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474

◆ convertToGLFormat()

QImage QGLWidget::convertToGLFormat ( const QImage img)
static

Converts the image img into the unnamed format expected by OpenGL functions such as glTexImage2D().

The returned image is not usable as a QImage, but QImage::width(), QImage::height() and QImage::bits() may be used with OpenGL. The GL format used is GL_RGBA.

Warning
This function is not part of the public interface. ###

opengl/texture example The following few lines are from the texture example. Most of the code is irrelevant, so we just quote the relevant bits:

opengl/texture/gltexobj.cpp tex1 tex1 gllogo.bmp

We create tex1 (and another variable) for OpenGL, and load a real image into buf.

convertToGLFormat convertToGLFormat

A few lines later, we convert buf into OpenGL format and store it in tex1.

glTexImage2D glTexImage2D tex1.bits

Note the dimension restrictions for texture images as described in the glTexImage2D() documentation. The width must be 2^m + 2*border and the height 2^n + 2*border where m and n are integers and border is either 0 or 1.

Another function in the same example uses tex1 with OpenGL.

Definition at line 4924 of file qgl.cpp.

4925 {
4926  QImage res(img.size(), QImage::Format_ARGB32);
4928  return res;
4929 }
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QSize size() const
Returns the size of the image, i.
Definition: qimage.cpp:1587
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
#define GL_RGBA
static void convertToGLFormatHelper(QImage &dst, const QImage &img, GLenum texture_format)
Definition: qgl.cpp:2286

◆ deleteTexture()

void QGLWidget::deleteTexture ( GLuint  id)

Calls QGLContext::deleteTexture(id) on the currently set context.

See also
bindTexture()

Definition at line 5457 of file qgl.cpp.

5458 {
5459  Q_D(QGLWidget);
5460  d->glcx->deleteTexture(id);
5461 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474

◆ doneCurrent()

void QGLWidget::doneCurrent ( )

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.

Definition at line 4204 of file qgl.cpp.

4205 {
4206  Q_D(QGLWidget);
4207  d->glcx->doneCurrent();
4208 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474

◆ doubleBuffer()

bool QGLWidget::doubleBuffer ( ) const

Returns true if the contained GL rendering context has double buffering; otherwise returns false.

See also
QGLFormat::doubleBuffer()

Definition at line 5309 of file qgl.cpp.

5310 {
5311  Q_D(const QGLWidget);
5312  return d->glcx->d_ptr->glFormat.testOption(QGL::DoubleBuffer);
5313 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474

◆ drawTexture() [1/2]

void QGLWidget::drawTexture ( const QRectF target,
GLuint  textureId,
GLenum  textureTarget = GL_TEXTURE_2D 
)

Calls the corresponding QGLContext::drawTexture() with target, textureId, and textureTarget for this widget's context.

Since
4.4

Definition at line 5482 of file qgl.cpp.

5483 {
5484  Q_D(QGLWidget);
5485  d->glcx->drawTexture(target, textureId, textureTarget);
5486 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474

◆ drawTexture() [2/2]

void QGLWidget::drawTexture ( const QPointF point,
GLuint  textureId,
GLenum  textureTarget = GL_TEXTURE_2D 
)

Calls the corresponding QGLContext::drawTexture() with point, textureId, and textureTarget for this widget's context.

Since
4.4

Definition at line 5507 of file qgl.cpp.

5508 {
5509  Q_D(QGLWidget);
5510  d->glcx->drawTexture(point, textureId, textureTarget);
5511 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474

◆ event()

bool QGLWidget::event ( QEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 347 of file qgl_qpa.cpp.

Referenced by qStoreColors(), and qt_egl_create_surface().

348 {
349  return QWidget::event(e);
350 }
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636

◆ fontDisplayListBase()

int QGLWidget::fontDisplayListBase ( const QFont font,
int  listBase = 2000 
)
protected

Returns the value of the first display list that is generated for the characters in the given font.

listBase indicates the base value used when generating the display lists for the font. The default value is 2000.

Note
This function is not supported on OpenGL/ES systems.

Definition at line 4976 of file qgl.cpp.

4977 {
4978 #ifndef QT_OPENGL_ES
4979  Q_D(QGLWidget);
4980  int base;
4981 
4982  if (!d->glcx) { // this can't happen unless we run out of mem
4983  return 0;
4984  }
4985 
4986  // always regenerate font disp. lists for pixmaps - hw accelerated
4987  // contexts can't handle this otherwise
4988  bool regenerate = d->glcx->deviceIsPixmap();
4989 #ifndef QT_NO_FONTCONFIG
4990  // font color needs to be part of the font cache key when using
4991  // antialiased fonts since one set of glyphs needs to be generated
4992  // for each font color
4993  QString color_key;
4994  if (font.styleStrategy() != QFont::NoAntialias) {
4995  GLfloat color[4];
4996  glGetFloatv(GL_CURRENT_COLOR, color);
4997  color_key.sprintf("%f_%f_%f",color[0], color[1], color[2]);
4998  }
4999  QString key = font.key() + color_key + QString::number((int) regenerate);
5000 #else
5001  QString key = font.key() + QString::number((int) regenerate);
5002 #endif
5003  if (!regenerate && (d->displayListCache.find(key) != d->displayListCache.end())) {
5004  base = d->displayListCache[key];
5005  } else {
5006  int maxBase = listBase - 256;
5008  for (it = d->displayListCache.constBegin(); it != d->displayListCache.constEnd(); ++it) {
5009  if (maxBase < it.value()) {
5010  maxBase = it.value();
5011  }
5012  }
5013  maxBase += 256;
5014  d->glcx->generateFontDisplayLists(font, maxBase);
5015  d->displayListCache[key] = maxBase;
5016  base = maxBase;
5017  }
5018  return base;
5019 #else // QT_OPENGL_ES
5020  Q_UNUSED(font);
5021  Q_UNUSED(listBase);
5022  return 0;
5023 #endif
5024 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
double d
Definition: qnumeric_p.h:62
QString & sprintf(const char *format,...)
Safely builds a formatted string from the format string cformat and an arbitrary list of arguments...
Definition: qstring.cpp:5567
#define it(className, varName)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
static const uint base
Definition: qurl.cpp:268
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474
int key
QString key() const
Returns the font&#39;s key, a textual representation of a font.
Definition: qfont.cpp:2332
StyleStrategy styleStrategy() const
Returns the StyleStrategy.
Definition: qfont.cpp:1447
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67

◆ format()

QGLFormat QGLWidget::format ( ) const

Returns the format of the contained GL rendering context.

Definition at line 5297 of file qgl.cpp.

5298 {
5299  Q_D(const QGLWidget);
5300  return d->glcx->format();
5301 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474

◆ glDraw()

void QGLWidget::glDraw ( )
protectedvirtual

Executes the virtual function paintGL().

The widget's rendering context will become the current context and initializeGL() will be called if it hasn't already been called.

Definition at line 4790 of file qgl.cpp.

4791 {
4792  Q_D(QGLWidget);
4793  if (!isValid())
4794  return;
4795 #ifdef Q_OS_SYMBIAN
4796  // Crashes on Symbian if trying to render to invisible surfaces
4797  if (!isVisible() && d->glcx->device()->devType() == QInternal::Widget)
4798  return;
4799 #endif
4800  makeCurrent();
4801 #ifndef QT_OPENGL_ES
4802  if (d->glcx->deviceIsPixmap())
4803  glDrawBuffer(GL_FRONT);
4804 #endif
4805  if (!d->glcx->initialized()) {
4806  glInit();
4807  resizeGL(d->glcx->device()->width(), d->glcx->device()->height()); // New context needs this "resize"
4808  }
4809  paintGL();
4810  if (doubleBuffer()) {
4811  if (d->autoSwap)
4812  swapBuffers();
4813  } else {
4814  glFlush();
4815  }
4816 }
double d
Definition: qnumeric_p.h:62
virtual void glInit()
Initializes OpenGL for this widget&#39;s context.
Definition: qgl.cpp:4772
void makeCurrent()
Makes this widget the current widget for OpenGL operations, i.
Definition: qgl.cpp:4187
bool isVisible() const
Definition: qwidget.h:1005
#define Q_D(Class)
Definition: qglobal.h:2482
virtual void resizeGL(int w, int h)
This virtual function is called whenever the widget has been resized.
Definition: qgl.cpp:4408
bool isValid() const
Returns true if the widget has a valid GL rendering context; otherwise returns false.
Definition: qgl.cpp:4151
void swapBuffers()
Swaps the screen contents with an off-screen buffer.
Definition: qgl.cpp:4226
#define GL_FRONT
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474
virtual void paintGL()
This virtual function is called whenever the widget needs to be painted.
Definition: qgl.cpp:4389
bool doubleBuffer() const
Returns true if the contained GL rendering context has double buffering; otherwise returns false...
Definition: qgl.cpp:5309

◆ glInit()

void QGLWidget::glInit ( )
protectedvirtual

Initializes OpenGL for this widget's context.

Calls the virtual function initializeGL().

Definition at line 4772 of file qgl.cpp.

Referenced by QGLOverlayWidget::paintGL().

4773 {
4774  Q_D(QGLWidget);
4775  if (!isValid())
4776  return;
4777  makeCurrent();
4778  initializeGL();
4779  d->glcx->setInitialized(true);
4780 }
double d
Definition: qnumeric_p.h:62
void makeCurrent()
Makes this widget the current widget for OpenGL operations, i.
Definition: qgl.cpp:4187
#define Q_D(Class)
Definition: qglobal.h:2482
bool isValid() const
Returns true if the widget has a valid GL rendering context; otherwise returns false.
Definition: qgl.cpp:4151
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474
virtual void initializeGL()
This virtual function is called once before the first call to paintGL() or resizeGL(), and then once whenever the widget has been assigned a new QGLContext.
Definition: qgl.cpp:4376

◆ grabFrameBuffer()

QImage QGLWidget::grabFrameBuffer ( bool  withAlpha = false)

Returns an image of the frame buffer.

If withAlpha is true the alpha channel is included.

Depending on your hardware, you can explicitly select which color buffer to grab with a glReadBuffer() call before calling this function.

Definition at line 4740 of file qgl.cpp.

4741 {
4742  makeCurrent();
4743  QImage res;
4744  int w = width();
4745  int h = height();
4746  if (format().rgba()) {
4747  res = qt_gl_read_framebuffer(QSize(w, h), format().alpha(), withAlpha);
4748  } else {
4749 #if defined (Q_WS_WIN) && !defined(QT_OPENGL_ES)
4750  res = QImage(w, h, QImage::Format_Indexed8);
4751  glReadPixels(0, 0, w, h, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, res.bits());
4753  if (pal.size()) {
4754  res.setColorCount(pal.size());
4755  for (int i = 0; i < pal.size(); i++)
4756  res.setColor(i, pal.at(i).rgb());
4757  }
4758  res = res.mirrored();
4759 #endif
4760  }
4761 
4762  return res;
4763 }
static QColormap instance(int screen=-1)
void makeCurrent()
Makes this widget the current widget for OpenGL operations, i.
Definition: qgl.cpp:4187
void setColor(int i, QRgb c)
Sets the color at the given index in the color table, to the given to colorValue. ...
Definition: qimage.cpp:1850
int height() const
QGLFormat format() const
Returns the format of the contained GL rendering context.
Definition: qgl.cpp:5297
void setColorCount(int)
Resizes the color table to contain colorCount entries.
Definition: qimage.cpp:2275
int width() const
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QImage mirrored(bool horizontally=false, bool vertically=true) const
Returns a mirror of the image, mirrored in the horizontal and/or the vertical direction depending on ...
Definition: qimage.cpp:4922
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
#define GL_UNSIGNED_BYTE
const QVector< QColor > colormap() const
QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include_alpha)
Definition: qgl.cpp:1860
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ initializeGL()

void QGLWidget::initializeGL ( )
protectedvirtual

This virtual function is called once before the first call to paintGL() or resizeGL(), and then once whenever the widget has been assigned a new QGLContext.

Reimplement it in a subclass.

This function should set up any required OpenGL context rendering flags, defining display lists, etc.

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

Reimplemented in QGLOverlayWidget.

Definition at line 4376 of file qgl.cpp.

4377 {
4378 }

◆ initializeOverlayGL()

void QGLWidget::initializeOverlayGL ( )
protectedvirtual

This virtual function is used in the same manner as initializeGL() 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 paintOverlayGL() or resizeOverlayGL(). Reimplement it in a subclass.

This function should set up any required OpenGL context rendering flags, defining display lists, etc. for the overlay context.

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

Definition at line 4428 of file qgl.cpp.

Referenced by QGLOverlayWidget::initializeGL().

4429 {
4430 }

◆ isSharing()

bool QGLWidget::isSharing ( ) const

Returns true 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.

See also
format()

Definition at line 4170 of file qgl.cpp.

4171 {
4172  Q_D(const QGLWidget);
4173  return d->glcx->isSharing();
4174 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474

◆ isValid()

bool QGLWidget::isValid ( ) const

Returns true if the widget has a valid GL rendering context; otherwise returns false.

A widget will be invalid if the system has no OpenGL support.

Definition at line 4151 of file qgl.cpp.

Referenced by QGLOverlayWidget::paintGL().

4152 {
4153  Q_D(const QGLWidget);
4154  return d->glcx && d->glcx->isValid();
4155 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474

◆ makeCurrent()

void QGLWidget::makeCurrent ( )

Makes this widget the current widget for OpenGL operations, i.

e. makes the widget's rendering context the current OpenGL rendering context.

Definition at line 4187 of file qgl.cpp.

Referenced by QGLOverlayWidget::paintGL().

4188 {
4189  Q_D(QGLWidget);
4190  d->glcx->makeCurrent();
4191 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474

◆ makeOverlayCurrent()

void QGLWidget::makeOverlayCurrent ( )

Makes the overlay context of this widget current.

Use this if you need to issue OpenGL commands to the overlay context outside of initializeOverlayGL(), resizeOverlayGL(), and paintOverlayGL().

Does nothing if this widget has no overlay.

See also
makeCurrent()

Definition at line 924 of file qgl_mac.mm.

Referenced by event(), QGLOverlayWidget::paintGL(), qStoreColors(), qt_egl_create_surface(), and QGLWidgetPrivate::updateColormap().

925 {
926 }

◆ overlayContext()

const QGLContext * QGLWidget::overlayContext ( ) const

Returns the overlay context of this widget, or 0 if this widget has no overlay.

See also
context()

Definition at line 919 of file qgl_mac.mm.

Referenced by QGLContext::choosePixelFormat(), event(), QGLOverlayWidget::paintGL(), qStoreColors(), qt_egl_create_surface(), and QGLWidgetPrivate::updateColormap().

920 {
921  return 0;
922 }

◆ paintEngine()

QPaintEngine * QGLWidget::paintEngine ( ) const
virtual

Returns the GL widget's paint engine.

Warning
This function is not part of the public interface.

This is normally a QOpenGLPaintEngine.

Reimplemented from QWidget.

Definition at line 5553 of file qgl.cpp.

5554 {
5555  return qt_qgl_paint_engine();
5556 }
Q_OPENGL_EXPORT QPaintEngine * qt_qgl_paint_engine()
Definition: qgl.cpp:5530

◆ paintEvent()

void QGLWidget::paintEvent ( QPaintEvent event)
protectedvirtual

Handles paint events passed in the event parameter.

Will cause the virtual paintGL() function to be called.

The widget's rendering context will become the current context and initializeGL() will be called if it hasn't already been called.

Reimplemented from QWidget.

Definition at line 4601 of file qgl.cpp.

4602 {
4603  if (updatesEnabled()) {
4604  glDraw();
4605  updateOverlayGL();
4606  }
4607 }
virtual void glDraw()
Executes the virtual function paintGL().
Definition: qgl.cpp:4790
bool updatesEnabled() const
virtual void updateOverlayGL()
Updates the widget&#39;s overlay (if any).
Definition: qgl_mac.mm:928

◆ paintGL()

void QGLWidget::paintGL ( )
protectedvirtual

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 this function is called.

Reimplemented in QGLOverlayWidget.

Definition at line 4389 of file qgl.cpp.

4390 {
4391 }

◆ paintOverlayGL()

void QGLWidget::paintOverlayGL ( )
protectedvirtual

This virtual function is used in the same manner as paintGL() 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.

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

Definition at line 4444 of file qgl.cpp.

Referenced by QGLOverlayWidget::paintGL().

4445 {
4446 }

◆ qglClearColor()

void QGLWidget::qglClearColor ( const QColor c) const

Convenience function for specifying the clearing color to OpenGL.

Calls glClearColor (in RGBA mode) or glClearIndex (in color-index mode) with the color c. Applies to this widgets GL context.

See also
qglColor(), QGLContext::currentContext(), QColor

Definition at line 4861 of file qgl.cpp.

Referenced by QGLOverlayWidget::initializeGL().

4862 {
4863 #ifdef QT_OPENGL_ES
4864  glClearColor(c.redF(), c.greenF(), c.blueF(), c.alphaF());
4865 #else
4866  Q_D(const QGLWidget);
4868  if (ctx) {
4869  if (ctx->format().rgba())
4870  glClearColor(c.redF(), c.greenF(), c.blueF(), c.alphaF());
4871  else if (!d->cmap.isEmpty()) { // QGLColormap in use?
4872  int i = d->cmap.find(c.rgb());
4873  if (i < 0)
4874  i = d->cmap.findNearest(c.rgb());
4875  glClearIndex(i);
4876  } else
4877  glClearIndex(ctx->colorIndex(c));
4878  }
4879 #endif
4880 }
double d
Definition: qnumeric_p.h:62
qreal alphaF() const
Returns the alpha color component of this color.
Definition: qcolor.cpp:1106
bool rgba() const
Returns true if RGBA color mode is set.
Definition: qgl.h:623
qreal greenF() const
Returns the green color component of this color.
Definition: qcolor.cpp:1241
#define Q_D(Class)
Definition: qglobal.h:2482
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
QGLFormat format() const
Returns the frame buffer format that was obtained (this may be a subset of what was requested)...
Definition: qgl.cpp:3495
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474
qreal redF() const
Returns the red color component of this color.
Definition: qcolor.cpp:1213
#define ctx
Definition: qgl.cpp:6094
qreal blueF() const
Returns the blue color component of this color.
Definition: qcolor.cpp:1269
uint colorIndex(const QColor &c) const
Returns a colormap index for the color c, in ColorIndex mode.
Definition: qgl_egl.cpp:367
QRgb rgb() const
Returns the RGB value of the color.
Definition: qcolor.cpp:1051

◆ qglColor()

void QGLWidget::qglColor ( const QColor c) const

Convenience function for specifying a drawing color to OpenGL.

Calls glColor4 (in RGBA mode) or glIndex (in color-index mode) with the color c. Applies to this widgets GL context.

Note
This function is not supported on OpenGL/ES 2.0 systems.
See also
qglClearColor(), QGLContext::currentContext(), QColor

Definition at line 4828 of file qgl.cpp.

4829 {
4830 #if !defined(QT_OPENGL_ES_2)
4831 #ifdef QT_OPENGL_ES
4832  glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF());
4833 #else
4834  Q_D(const QGLWidget);
4836  if (ctx) {
4837  if (ctx->format().rgba())
4838  glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF());
4839  else if (!d->cmap.isEmpty()) { // QGLColormap in use?
4840  int i = d->cmap.find(c.rgb());
4841  if (i < 0)
4842  i = d->cmap.findNearest(c.rgb());
4843  glIndexi(i);
4844  } else
4845  glIndexi(ctx->colorIndex(c));
4846  }
4847 #endif //QT_OPENGL_ES
4848 #else
4849  Q_UNUSED(c);
4850 #endif //QT_OPENGL_ES_2
4851 }
double d
Definition: qnumeric_p.h:62
qreal alphaF() const
Returns the alpha color component of this color.
Definition: qcolor.cpp:1106
bool rgba() const
Returns true if RGBA color mode is set.
Definition: qgl.h:623
qreal greenF() const
Returns the green color component of this color.
Definition: qcolor.cpp:1241
#define Q_D(Class)
Definition: qglobal.h:2482
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
QGLFormat format() const
Returns the frame buffer format that was obtained (this may be a subset of what was requested)...
Definition: qgl.cpp:3495
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474
qreal redF() const
Returns the red color component of this color.
Definition: qcolor.cpp:1213
#define ctx
Definition: qgl.cpp:6094
qreal blueF() const
Returns the blue color component of this color.
Definition: qcolor.cpp:1269
uint colorIndex(const QColor &c) const
Returns a colormap index for the color c, in ColorIndex mode.
Definition: qgl_egl.cpp:367
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QRgb rgb() const
Returns the RGB value of the color.
Definition: qcolor.cpp:1051

◆ renderPixmap()

QPixmap QGLWidget::renderPixmap ( int  w = 0,
int  h = 0,
bool  useContext = false 
)

Renders the current scene on a pixmap and returns the pixmap.

You can use this method on both visible and invisible QGLWidget objects.

This method will create a pixmap and a temporary QGLContext to render on the pixmap. It will then call initializeGL(), resizeGL(), and paintGL() on this context. Finally, the widget's original GL context is restored.

The size of the pixmap will be w pixels wide and h pixels high unless one of these parameters is 0 (the default), in which case the pixmap will have the same size as the widget.

If useContext is true, this method will try to be more efficient by using the existing GL context to render the pixmap. The default is false. Only use true if you understand the risks. Note that under Windows a temporary context has to be created and usage of the useContext parameter is not supported.

Overlays are not rendered onto the pixmap.

If the GL rendering context and the desktop have different bit depths, the result will most likely look surprising.

Note that the creation of display lists, modifications of the view frustum etc. should be done from within initializeGL(). If this is not done, the temporary QGLContext will not be initialized properly, and the rendered pixmap may be incomplete/corrupted.

Definition at line 4660 of file qgl.cpp.

4661 {
4662  Q_D(QGLWidget);
4663  QSize sz = size();
4664  if ((w > 0) && (h > 0))
4665  sz = QSize(w, h);
4666 
4667 #if defined(Q_WS_X11)
4668  extern int qt_x11_preferred_pixmap_depth;
4669  int old_depth = qt_x11_preferred_pixmap_depth;
4670  qt_x11_preferred_pixmap_depth = x11Info().depth();
4671 
4673  data->resize(sz.width(), sz.height());
4674  QPixmap pm(data);
4675  qt_x11_preferred_pixmap_depth = old_depth;
4676  QX11Info xinfo = x11Info();
4677 
4678  // make sure we use a pixmap with the same depth/visual as the widget
4679  if (xinfo.visual() != QX11Info::appVisual()) {
4680  QX11InfoData* xd = pm.x11Info().getX11Data(true);
4681  xd->depth = xinfo.depth();
4682  xd->visual = static_cast<Visual *>(xinfo.visual());
4683  const_cast<QX11Info &>(pm.x11Info()).setX11Data(xd);
4684  }
4685 
4686 #else
4687  QPixmap pm(sz);
4688 #endif
4689 
4690  d->glcx->doneCurrent();
4691 
4692  bool success = true;
4693 
4694  if (useContext && isValid() && d->renderCxPm(&pm))
4695  return pm;
4696 
4697  QGLFormat fmt = d->glcx->requestedFormat();
4698  fmt.setDirectRendering(false); // Direct is unlikely to work
4699  fmt.setDoubleBuffer(false); // We don't need dbl buf
4700 #ifdef Q_WS_MAC // crash prevention on the Mac - it's unlikely to work anyway
4701  fmt.setSampleBuffers(false);
4702 #endif
4703 
4704  QGLContext* ocx = d->glcx;
4705  ocx->doneCurrent();
4706  d->glcx = new QGLContext(fmt, &pm);
4707  d->glcx->create();
4708 
4709  if (d->glcx->isValid())
4710  updateGL();
4711  else
4712  success = false;
4713 
4714  delete d->glcx;
4715  d->glcx = ocx;
4716 
4717  ocx->makeCurrent();
4718 
4719  if (success) {
4720 #if defined(Q_WS_X11)
4721  if (xinfo.visual() != QX11Info::appVisual()) {
4722  QImage image = pm.toImage();
4723  QPixmap p = QPixmap::fromImage(image);
4724  return p;
4725  }
4726 #endif
4727  return pm;
4728  }
4729  return QPixmap();
4730 }
double d
Definition: qnumeric_p.h:62
int depth() const
Returns the color depth (bits per pixel) of the X display.
friend class QGLContext
Definition: qgl.h:600
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition: qpixmap.cpp:2197
QSize size() const
virtual void resize(int width, int height)=0
const QX11Info & x11Info() const
Returns information about the configuration of the X display used to display the widget.
void setSampleBuffers(bool enable)
If enable is true, a GL context with multisample buffer support is picked; otherwise ignored...
Definition: qgl.cpp:812
#define Q_D(Class)
Definition: qglobal.h:2482
void setDirectRendering(bool enable)
If enable is true enables direct rendering; otherwise disables direct rendering.
Definition: qgl.cpp:787
int width() const
Returns the width.
Definition: qsize.h:126
bool isValid() const
Returns true if the widget has a valid GL rendering context; otherwise returns false.
Definition: qgl.cpp:4151
friend class QPixmap
Definition: qwidget.h:748
The QGLFormat class specifies the display format of an OpenGL rendering context.
Definition: qgl.h:175
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
QWidgetData * data
Definition: qwidget.h:815
void setDoubleBuffer(bool enable)
If enable is true sets double buffering; otherwise sets single buffering.
Definition: qgl.cpp:566
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
void * visual() const
Returns the current visual.
Visual * visual
Definition: qt_x11_p.h:318
int Q_GUI_EXPORT qt_x11_preferred_pixmap_depth
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474
The QX11Info class provides information about the X display configuration.
Definition: qx11info_x11.h:63
static void * appVisual(int screen=-1)
Returns the current visual used by the application on the given screen.
virtual void updateGL()
Updates the widget by calling glDraw().
Definition: qgl.cpp:4343
virtual void doneCurrent()
Makes no GL context the current context.
Definition: qgl_egl.cpp:277
int height() const
Returns the height.
Definition: qsize.h:129
virtual void makeCurrent()
Makes this context the current OpenGL rendering context.
Definition: qgl_egl.cpp:213
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ renderText() [1/2]

void QGLWidget::renderText ( int  x,
int  y,
const QString str,
const QFont font = QFont(),
int  listBase = 2000 
)

Renders the string str into the GL context of this widget.

x and y are specified in window coordinates, with the origin in the upper left-hand corner of the window. If font 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 qglColor() convenience function), just before the renderText() call.

The listBase parameter is obsolete and will be removed in a future version of Qt.

Note
This function clears the stencil buffer.
This function is not supported on OpenGL/ES systems.
This function temporarily disables depth-testing when the text is drawn.
This function can only be used inside a QPainter::beginNativePainting()/QPainter::endNativePainting() block if the default OpenGL paint engine is QPaintEngine::OpenGL. To make QPaintEngine::OpenGL the default GL engine, call QGL::setPreferredPaintEngine(QPaintEngine::OpenGL) before the QApplication constructor.

Overpainting Example{Overpaint} with QPainter::drawText() instead.

Definition at line 5112 of file qgl.cpp.

5113 {
5114 #ifndef QT_OPENGL_ES
5115  Q_D(QGLWidget);
5116  if (str.isEmpty() || !isValid())
5117  return;
5118 
5119  GLint view[4];
5120  bool use_scissor_testing = glIsEnabled(GL_SCISSOR_TEST);
5121  if (!use_scissor_testing)
5122  glGetIntegerv(GL_VIEWPORT, &view[0]);
5123  int width = d->glcx->device()->width();
5124  int height = d->glcx->device()->height();
5125  bool auto_swap = autoBufferSwap();
5126 
5127  QPaintEngine::Type oldEngineType = qgl_engine_selector()->preferredPaintEngine();
5128 
5129  QPaintEngine *engine = paintEngine();
5130  if (engine && (oldEngineType == QPaintEngine::OpenGL2) && engine->isActive()) {
5131  qWarning("QGLWidget::renderText(): Calling renderText() while a GL 2 paint engine is"
5132  " active on the same device is not allowed.");
5133  return;
5134  }
5135 
5136  // this changes what paintEngine() returns
5137  qgl_engine_selector()->setPreferredPaintEngine(QPaintEngine::OpenGL);
5138  engine = paintEngine();
5139  QPainter *p;
5140  bool reuse_painter = false;
5141  if (engine->isActive()) {
5142  reuse_painter = true;
5143  p = engine->painter();
5144  qt_save_gl_state();
5145 
5146  glDisable(GL_DEPTH_TEST);
5147  glViewport(0, 0, width, height);
5148  glMatrixMode(GL_PROJECTION);
5149  glLoadIdentity();
5150  glOrtho(0, width, height, 0, 0, 1);
5151  glMatrixMode(GL_MODELVIEW);
5152 
5153  glLoadIdentity();
5154  } else {
5155  setAutoBufferSwap(false);
5156  // disable glClear() as a result of QPainter::begin()
5157  d->disable_clear_on_painter_begin = true;
5158  p = new QPainter(this);
5159  }
5160 
5161  QRect viewport(view[0], view[1], view[2], view[3]);
5162  if (!use_scissor_testing && viewport != rect()) {
5163  // if the user hasn't set a scissor box, we set one that
5164  // covers the current viewport
5165  glScissor(view[0], view[1], view[2], view[3]);
5166  glEnable(GL_SCISSOR_TEST);
5167  } else if (use_scissor_testing) {
5168  // use the scissor box set by the user
5169  glEnable(GL_SCISSOR_TEST);
5170  }
5171 
5172  qt_gl_draw_text(p, x, y, str, font);
5173 
5174  if (reuse_painter) {
5176  } else {
5177  p->end();
5178  delete p;
5179  setAutoBufferSwap(auto_swap);
5180  d->disable_clear_on_painter_begin = false;
5181  }
5182  qgl_engine_selector()->setPreferredPaintEngine(oldEngineType);
5183 #else // QT_OPENGL_ES
5184  Q_UNUSED(x);
5185  Q_UNUSED(y);
5186  Q_UNUSED(str);
5187  Q_UNUSED(font);
5188  qWarning("QGLWidget::renderText is not supported under OpenGL/ES");
5189 #endif
5190 }
QPaintEngine * paintEngine() const
Returns the GL widget&#39;s paint engine.
Definition: qgl.cpp:5553
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
void setAutoBufferSwap(bool on)
If on is true automatic GL buffer swapping is switched on; otherwise it is switched off...
Definition: qgl.cpp:5315
int y() const
#define GL_DEPTH_TEST
static void qt_save_gl_state()
Definition: qgl.cpp:5028
#define Q_D(Class)
Definition: qglobal.h:2482
int height() const
#define GL_SCISSOR_TEST
bool isValid() const
Returns true if the widget has a valid GL rendering context; otherwise returns false.
Definition: qgl.cpp:4151
QPainter * painter() const
Returns the paint engine&#39;s painter.
bool isActive() const
Returns true if the paint engine is actively drawing; otherwise returns false.
Definition: qpaintengine.h:154
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
int width() const
Q_CORE_EXPORT void qWarning(const char *,...)
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:90
QRect rect() const
static void qt_restore_gl_state()
Definition: qgl.cpp:5049
bool autoBufferSwap() const
Returns true if the widget is doing automatic GL buffer swapping; otherwise returns false...
Definition: qgl.cpp:5321
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474
int x() const
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
typedef GLint
Definition: glfunctions.h:67
friend class QPainter
Definition: qwidget.h:746
#define GL_VIEWPORT
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
static void qt_gl_draw_text(QPainter *p, int x, int y, const QString &str, const QFont &font)
Definition: qgl.cpp:5061
bool end()
Ends painting.
Definition: qpainter.cpp:1929

◆ renderText() [2/2]

void QGLWidget::renderText ( double  x,
double  y,
double  z,
const QString str,
const QFont font = QFont(),
int  listBase = 2000 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.x, y and z 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.

Note
This function is not supported on OpenGL/ES systems.
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 glDisable(GL_DEPTH_TEST) before calling this function to annotate the models without depth-testing the text.

Overpainting Example{Overpaint} with QPainter::drawText() instead.

Definition at line 5209 of file qgl.cpp.

5210 {
5211 #ifndef QT_OPENGL_ES
5212  Q_D(QGLWidget);
5213  if (str.isEmpty() || !isValid())
5214  return;
5215 
5216  bool auto_swap = autoBufferSwap();
5217 
5218  int width = d->glcx->device()->width();
5219  int height = d->glcx->device()->height();
5220  GLdouble model[4][4], proj[4][4];
5221  GLint view[4];
5222  glGetDoublev(GL_MODELVIEW_MATRIX, &model[0][0]);
5223  glGetDoublev(GL_PROJECTION_MATRIX, &proj[0][0]);
5224  glGetIntegerv(GL_VIEWPORT, &view[0]);
5225  GLdouble win_x = 0, win_y = 0, win_z = 0;
5226  qgluProject(x, y, z, &model[0][0], &proj[0][0], &view[0],
5227  &win_x, &win_y, &win_z);
5228  win_y = height - win_y; // y is inverted
5229 
5230  QPaintEngine::Type oldEngineType = qgl_engine_selector()->preferredPaintEngine();
5231  QPaintEngine *engine = paintEngine();
5232 
5233  if (engine && (oldEngineType == QPaintEngine::OpenGL2) && engine->isActive()) {
5234  qWarning("QGLWidget::renderText(): Calling renderText() while a GL 2 paint engine is"
5235  " active on the same device is not allowed.");
5236  return;
5237  }
5238 
5239  // this changes what paintEngine() returns
5240  qgl_engine_selector()->setPreferredPaintEngine(QPaintEngine::OpenGL);
5241  engine = paintEngine();
5242  QPainter *p;
5243  bool reuse_painter = false;
5244  bool use_depth_testing = glIsEnabled(GL_DEPTH_TEST);
5245  bool use_scissor_testing = glIsEnabled(GL_SCISSOR_TEST);
5246 
5247  if (engine->isActive()) {
5248  reuse_painter = true;
5249  p = engine->painter();
5250  qt_save_gl_state();
5251  } else {
5252  setAutoBufferSwap(false);
5253  // disable glClear() as a result of QPainter::begin()
5254  d->disable_clear_on_painter_begin = true;
5255  p = new QPainter(this);
5256  }
5257 
5258  QRect viewport(view[0], view[1], view[2], view[3]);
5259  if (!use_scissor_testing && viewport != rect()) {
5260  glScissor(view[0], view[1], view[2], view[3]);
5261  glEnable(GL_SCISSOR_TEST);
5262  } else if (use_scissor_testing) {
5263  glEnable(GL_SCISSOR_TEST);
5264  }
5265  glMatrixMode(GL_PROJECTION);
5266  glLoadIdentity();
5267  glViewport(0, 0, width, height);
5268  glOrtho(0, width, height, 0, 0, 1);
5269  glMatrixMode(GL_MODELVIEW);
5270  glLoadIdentity();
5271  glAlphaFunc(GL_GREATER, 0.0);
5272  glEnable(GL_ALPHA_TEST);
5273  if (use_depth_testing)
5274  glEnable(GL_DEPTH_TEST);
5275  glTranslated(0, 0, -win_z);
5276  qt_gl_draw_text(p, qRound(win_x), qRound(win_y), str, font);
5277 
5278  if (reuse_painter) {
5280  } else {
5281  p->end();
5282  delete p;
5283  setAutoBufferSwap(auto_swap);
5284  d->disable_clear_on_painter_begin = false;
5285  }
5286  qgl_engine_selector()->setPreferredPaintEngine(oldEngineType);
5287 #else // QT_OPENGL_ES
5288  Q_UNUSED(x);
5289  Q_UNUSED(y);
5290  Q_UNUSED(z);
5291  Q_UNUSED(str);
5292  Q_UNUSED(font);
5293  qWarning("QGLWidget::renderText is not supported under OpenGL/ES");
5294 #endif
5295 }
QPaintEngine * paintEngine() const
Returns the GL widget&#39;s paint engine.
Definition: qgl.cpp:5553
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
void setAutoBufferSwap(bool on)
If on is true automatic GL buffer swapping is switched on; otherwise it is switched off...
Definition: qgl.cpp:5315
int y() const
#define GL_DEPTH_TEST
static void qt_save_gl_state()
Definition: qgl.cpp:5028
#define Q_D(Class)
Definition: qglobal.h:2482
int height() const
#define GL_SCISSOR_TEST
bool isValid() const
Returns true if the widget has a valid GL rendering context; otherwise returns false.
Definition: qgl.cpp:4151
QPainter * painter() const
Returns the paint engine&#39;s painter.
bool isActive() const
Returns true if the paint engine is actively drawing; otherwise returns false.
Definition: qpaintengine.h:154
#define GL_GREATER
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
int width() const
Q_CORE_EXPORT void qWarning(const char *,...)
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:90
QRect rect() const
static GLint qgluProject(GLdouble objx, GLdouble objy, GLdouble objz, const GLdouble model[16], const GLdouble proj[16], const GLint viewport[4], GLdouble *winx, GLdouble *winy, GLdouble *winz)
Definition: qgl.cpp:402
static void qt_restore_gl_state()
Definition: qgl.cpp:5049
bool autoBufferSwap() const
Returns true if the widget is doing automatic GL buffer swapping; otherwise returns false...
Definition: qgl.cpp:5321
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474
int x() const
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
typedef GLint
Definition: glfunctions.h:67
friend class QPainter
Definition: qwidget.h:746
#define GL_VIEWPORT
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
static void qt_gl_draw_text(QPainter *p, int x, int y, const QString &str, const QFont &font)
Definition: qgl.cpp:5061
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
bool end()
Ends painting.
Definition: qpainter.cpp:1929

◆ resizeEvent()

void QGLWidget::resizeEvent ( QResizeEvent event)
protectedvirtual

Handles resize events that are passed in the event parameter.

Calls the virtual function resizeGL().

Reimplemented from QWidget.

Definition at line 896 of file qgl_mac.mm.

Referenced by event(), QGLOverlayWidget::paintGL(), qStoreColors(), qt_egl_create_surface(), and QGLWidgetPrivate::updateColormap().

897 {
898  Q_D(QGLWidget);
899  if (!isValid())
900  return;
901 #ifndef QT_MAC_USE_COCOA
902  if (!isWindow())
903  d->glcx->d_func()->update = true;
904 #endif
905  makeCurrent();
906  if (!d->glcx->initialized())
907  glInit();
908 #ifdef QT_MAC_USE_COCOA
909  d->glcx->updatePaintDevice();
910 #endif
911 #ifndef QT_MAC_USE_COCOA
912  float scale = qt_mac_get_scale_factor(this);
913  resizeGL(width() * scale, height() * scale);
914 #else
915  resizeGL(width(), height());
916 #endif
917 }
double d
Definition: qnumeric_p.h:62
virtual void glInit()
Initializes OpenGL for this widget&#39;s context.
Definition: qgl.cpp:4772
void makeCurrent()
Makes this widget the current widget for OpenGL operations, i.
Definition: qgl.cpp:4187
float qt_mac_get_scale_factor(QWidget *widget)
Definition: qgl_mac.mm:565
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
#define Q_D(Class)
Definition: qglobal.h:2482
int height() const
virtual void resizeGL(int w, int h)
This virtual function is called whenever the widget has been resized.
Definition: qgl.cpp:4408
bool isValid() const
Returns true if the widget has a valid GL rendering context; otherwise returns false.
Definition: qgl.cpp:4151
int width() const
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474

◆ resizeGL()

void QGLWidget::resizeGL ( int  width,
int  height 
)
protectedvirtual

This virtual function is called whenever the widget has been resized.

The new size is passed in width and height. Reimplement it in a subclass.

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

Reimplemented in QGLOverlayWidget.

Definition at line 4408 of file qgl.cpp.

4409 {
4410 }

◆ resizeOverlayGL()

void QGLWidget::resizeOverlayGL ( int  width,
int  height 
)
protectedvirtual

This virtual function is used in the same manner as paintGL() 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 width and height. Reimplement it in a subclass.

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

Definition at line 4465 of file qgl.cpp.

Referenced by QGLOverlayWidget::resizeGL().

4466 {
4467 }

◆ setAutoBufferSwap()

void QGLWidget::setAutoBufferSwap ( bool  on)
protected

If on is true automatic GL buffer swapping is switched on; otherwise it is switched off.

If on is true and the widget is using a double-buffered format, the background and foreground GL buffers will automatically be swapped after each paintGL() call.

The buffer auto-swapping is on by default.

See also
autoBufferSwap(), doubleBuffer(), swapBuffers()

Definition at line 5315 of file qgl.cpp.

5316 {
5317  Q_D(QGLWidget);
5318  d->autoSwap = on;
5319 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474

◆ setColormap()

void QGLWidget::setColormap ( const QGLColormap cmap)

Set the colormap for this widget to cmap.

Usually it is only top-level widgets that can have colormaps installed.

See also
colormap()

Definition at line 979 of file qgl_mac.mm.

Referenced by event(), qCanAllocColors(), qStoreColors(), qt_egl_create_surface(), and QGLWidgetPrivate::updateColormap().

980 {
981 }

◆ setContext()

void QGLWidget::setContext ( QGLContext context,
const QGLContext shareContext = 0,
bool  deleteOldContext = true 
)

Sets a new QGLContext, context, for this QGLWidget, using the shared context, shareContext.

Warning
This function is not part of the public interface.

If deleteOldContext is true, the original context is deleted; otherwise it is overridden.

Definition at line 932 of file qgl_mac.mm.

Referenced by QGLOverlayWidget::paintGL(), qDeleteQGLContext(), qStoreColors(), qt_egl_create_surface(), and QGLWidgetPrivate::updateColormap().

933 {
934  Q_D(QGLWidget);
935  if (context == 0) {
936  qWarning("QGLWidget::setContext: Cannot set null context");
937  return;
938  }
939 
940  if (d->glcx)
941  d->glcx->doneCurrent();
942  QGLContext* oldcx = d->glcx;
943  d->glcx = context;
944  if (!d->glcx->isValid())
945  d->glcx->create(shareContext ? shareContext : oldcx);
946  if (deleteOldContext && oldcx)
947  delete oldcx;
948 }
double d
Definition: qnumeric_p.h:62
const QGLContext * context() const
Returns the context of this widget.
Definition: qgl.cpp:5303
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
Q_CORE_EXPORT void qWarning(const char *,...)
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474

◆ setFormat()

void QGLWidget::setFormat ( const QGLFormat format)

Sets a new format for this widget.

If the underlying OpenGL/Window system cannot satisfy all the features requested in format, the nearest subset of features will be used. After creation, the format() method will return the actual rendering context format obtained.

The widget will be assigned a new QGLContext, and the initializeGL() function will be executed for this new context before the first resizeGL() or paintGL().

This method will try to keep display list and texture object sharing in effect with other QGLWidget objects, but changing the format might make sharing impossible. Use isSharing() to see if sharing is still in effect.

See also
format(), isSharing(), isValid()

Definition at line 4285 of file qgl.cpp.

4286 {
4287  setContext(new QGLContext(format,this));
4288 }
friend class QGLContext
Definition: qgl.h:600
void setContext(QGLContext *context, const QGLContext *shareContext=0, bool deleteOldContext=true)
Sets a new QGLContext, context, for this QGLWidget, using the shared context, shareContext.
Definition: qgl_mac.mm:932

◆ setMouseTracking()

void QGLWidget::setMouseTracking ( bool  enable)

If enable is true then mouse tracking is enabled; otherwise it is disabled.

Definition at line 357 of file qgl_egl.cpp.

Referenced by QGLOverlayWidget::paintGL(), qt_mac_get_widget_rgn(), and QGLWidgetPrivate::updateColormap().

358 {
360 }
void setMouseTracking(bool enable)
Definition: qwidget.h:990

◆ swapBuffers()

void QGLWidget::swapBuffers ( )

Swaps the screen contents with an off-screen buffer.

This only works if the widget's format specifies double buffer mode.

Normally, there is no need to explicitly call this function because it is done automatically after each widget repaint, i.e. each time after paintGL() has been executed.

See also
doubleBuffer(), setAutoBufferSwap(), QGLFormat::setDoubleBuffer()

Definition at line 4226 of file qgl.cpp.

4227 {
4228  Q_D(QGLWidget);
4229  d->glcx->swapBuffers();
4230 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474

◆ updateGL

void QGLWidget::updateGL ( )
virtualslot

Updates the widget by calling glDraw().

Definition at line 4343 of file qgl.cpp.

4344 {
4345  if (updatesEnabled())
4346  glDraw();
4347 }
virtual void glDraw()
Executes the virtual function paintGL().
Definition: qgl.cpp:4790
bool updatesEnabled() const

◆ updateOverlayGL

void QGLWidget::updateOverlayGL ( )
virtualslot

Updates the widget's overlay (if any).

Will cause the virtual function paintOverlayGL() to be executed.

The widget's rendering context will become the current context and initializeGL() will be called if it hasn't already been called.

Definition at line 928 of file qgl_mac.mm.

Referenced by event(), QGLOverlayWidget::paintGL(), qStoreColors(), qt_egl_create_surface(), and QGLWidgetPrivate::updateColormap().

929 {
930 }

Friends and Related Functions

◆ QGLContext

friend class QGLContext
friend

Definition at line 600 of file qgl.h.

Referenced by QGLPixelBufferPrivate::common_init().

◆ QGLContextPrivate

friend class QGLContextPrivate
friend

Definition at line 601 of file qgl.h.

◆ QGLDrawable

friend class QGLDrawable
friend

Definition at line 597 of file qgl.h.

◆ QGLOverlayWidget

friend class QGLOverlayWidget
friend

Definition at line 602 of file qgl.h.

◆ QGLPaintDevice

friend class QGLPaintDevice
friend

Definition at line 604 of file qgl.h.

◆ QGLPixelBuffer

friend class QGLPixelBuffer
friend

Definition at line 598 of file qgl.h.

◆ QGLPixelBufferPrivate

Definition at line 599 of file qgl.h.

◆ QGLWidgetGLPaintDevice

Definition at line 605 of file qgl.h.

◆ QMacGLWindowChangeEvent

friend class QMacGLWindowChangeEvent
friend

Definition at line 595 of file qgl.h.

◆ QOpenGLPaintEngine

friend class QOpenGLPaintEngine
friend

Definition at line 603 of file qgl.h.


The documentation for this class was generated from the following files: