En esta página

QOpenGLPaintDevice Class

La clase QOpenGLPaintDevice permite pintar en un contexto OpenGL usando QPainter. Más...

Cabecera: #include <QOpenGLPaintDevice>
CMake: find_package(Qt6 REQUIRED COMPONENTS OpenGL)
target_link_libraries(mytarget PRIVATE Qt6::OpenGL)
qmake: QT += opengl
Hereda: QPaintDevice

Funciones Públicas

QOpenGLPaintDevice()
QOpenGLPaintDevice(const QSize &size)
QOpenGLPaintDevice(int width, int height)
virtual ~QOpenGLPaintDevice()
QOpenGLContext *context() const
qreal dotsPerMeterX() const
qreal dotsPerMeterY() const
virtual void ensureActiveTarget()
bool paintFlipped() const
void setDevicePixelRatio(qreal devicePixelRatio)
void setDotsPerMeterX(qreal dpmx)
void setDotsPerMeterY(qreal dpmy)
void setPaintFlipped(bool flipped)
void setSize(const QSize &size)
QSize size() const

Funciones Públicas Reimplementadas

virtual QPaintEngine *paintEngine() const override

Funciones Protegidas Reimplementadas

virtual int metric(QPaintDevice::PaintDeviceMetric metric) const override

Descripción Detallada

El QOpenGLPaintDevice utiliza el contexto QOpenGL actual para renderizar comandos de dibujo QPainter. El contexto es capturado en la construcción. Requiere soporte para OpenGL (ES) 2.0 o superior.

Rendimiento

El QOpenGLPaintDevice es casi siempre acelerado por hardware y tiene el potencial de ser mucho más rápido que la rasterización por software. Sin embargo, es más sensible a los cambios de estado y, por tanto, requiere que los comandos de dibujo se ordenen cuidadosamente para conseguir un rendimiento óptimo.

Antialiasing y calidad

El antialiasing en el motor de pintura OpenGL se realiza mediante multimuestreo. La mayoría del hardware requiere mucha más memoria para realizar el multimuestreo y la calidad resultante no está a la altura de la calidad del motor de pintura por software. La fuerza del motor de pintura OpenGL reside en su rendimiento, no en su calidad de renderizado visual.

Cambios de estado

Cuando se pinta en un QOpenGLPaintDevice utilizando QPainter, el estado del contexto OpenGL actual será alterado por el motor de pintura para reflejar sus necesidades. Las aplicaciones no deben confiar en que el estado OpenGL se restablezca a sus condiciones originales, en particular el programa de sombreado actual, el viewport OpenGL, las unidades de textura y los modos de dibujo.

Mezclando QPainter y OpenGL

Cuando se entremezclan QPainter y OpenGL, es importante notificar a QPainter que el estado OpenGL puede haber sido desordenado para que pueda restaurar su estado interno. Esto se consigue llamando a QPainter::beginNativePainting() antes de comenzar el renderizado OpenGL y llamando a QPainter::endNativePainting() al terminar.

Ver también Ejemplo de Ventana OpenGL.

Documentación de las funciones miembro

QOpenGLPaintDevice::QOpenGLPaintDevice()

Construye un QOpenGLPaintDevice.

El QOpenGLPaintDevice solo es valido para el contexto actual.

Ver también QOpenGLContext::currentContext().

[explicit] QOpenGLPaintDevice::QOpenGLPaintDevice(const QSize &size)

Construye un QOpenGLPaintDevice con la dirección size.

El QOpenGLPaintDevice solo es valido para el contexto actual.

Ver también QOpenGLContext::currentContext().

QOpenGLPaintDevice::QOpenGLPaintDevice(int width, int height)

Construye un QOpenGLPaintDevice con los datos width y height.

El QOpenGLPaintDevice solo es valido para el contexto actual.

Ver también QOpenGLContext::currentContext().

[virtual noexcept] QOpenGLPaintDevice::~QOpenGLPaintDevice()

Destruye el QOpenGLPaintDevice.

QOpenGLContext *QOpenGLPaintDevice::context() const

Devuelve el contexto OpenGL asociado al dispositivo de pintura.

qreal QOpenGLPaintDevice::dotsPerMeterX() const

Devuelve el número de píxeles por metro horizontal.

Véase también setDotsPerMeterX().

qreal QOpenGLPaintDevice::dotsPerMeterY() const

Devuelve el número de píxeles por metro vertical.

Véase también setDotsPerMeterY().

[virtual] void QOpenGLPaintDevice::ensureActiveTarget()

Este método virtual se proporciona como llamada de retorno para permitir volver a vincular un objeto o contexto de memoria intermedia de fotogramas de destino cuando diferentes instancias de QOpenGLPaintDevice emiten llamadas a dibujo alternativamente.

beginNativePainting() también activará este método.

La implementación por defecto no hace nada.

[override virtual protected] int QOpenGLPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const

Reimplementa: QPaintDevice::metric(QPaintDevice::PaintDeviceMetric) const.

[override virtual] QPaintEngine *QOpenGLPaintDevice::paintEngine() const

Reimplementa: QPaintDevice::paintEngine() const.

bool QOpenGLPaintDevice::paintFlipped() const

Devuelve true si la pintura se voltea alrededor del eje Y.

Véase también setPaintFlipped().

void QOpenGLPaintDevice::setDevicePixelRatio(qreal devicePixelRatio)

Establece la relación de píxeles del dispositivo de pintura en devicePixelRatio.

void QOpenGLPaintDevice::setDotsPerMeterX(qreal dpmx)

Establece el número de píxeles por metro en horizontal en dpmx.

Véase también dotsPerMeterX().

void QOpenGLPaintDevice::setDotsPerMeterY(qreal dpmy)

Establece el número de píxeles por metro en vertical en dpmy.

Véase también dotsPerMeterY().

void QOpenGLPaintDevice::setPaintFlipped(bool flipped)

Establece si la pintura debe ser volteada alrededor del eje Y o no a flipped.

Véase también paintFlipped().

void QOpenGLPaintDevice::setSize(const QSize &size)

Establece el tamaño de píxel del dispositivo de pintura en size.

Véase también size().

QSize QOpenGLPaintDevice::size() const

Devuelve el tamaño en píxeles del dispositivo de pintura.

Véase también setSize().

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.