VTK
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
QVTKOpenGLWidget Class Reference

QWidget for displaying a vtkRenderWindow in a Qt Application. More...

#include <QVTKOpenGLWidget.h>

Inherits QWidget.

Public Member Functions

 QVTKOpenGLWidget (QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
 
 QVTKOpenGLWidget (QOpenGLContext *shareContext, QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
 
 QVTKOpenGLWidget (vtkGenericOpenGLRenderWindow *w, QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
 
 QVTKOpenGLWidget (vtkGenericOpenGLRenderWindow *w, QOpenGLContext *shareContext, QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
 
 ~QVTKOpenGLWidget () override
 
void setRenderWindow (vtkGenericOpenGLRenderWindow *win)
 Set a render window to use. More...
 
void setRenderWindow (vtkRenderWindow *win)
 
vtkRenderWindowrenderWindow () const
 Returns the render window that is being shown in this widget. More...
 
QVTKInteractorinteractor () const
 Get the QVTKInteractor that was either created by default or set by the user. More...
 
void setEnableHiDPI (bool enable)
 Enable or disable support for HiDPI displays. More...
 
bool enableHiDPI () const
 
void setUnscaledDPI (int dpi)
 Set/Get unscaled DPI value. More...
 
int unscaledDPI () const
 
void setDefaultCursor (const QCursor &cursor)
 Set/get the default cursor to use for this widget. More...
 
const QCursor & defaultCursor () const
 
bool isValid ()
 Returns true if the internal QOpenGLWindow's is valid, i.e. More...
 
QImage grabFramebuffer ()
 Expose internal QVTKOpenGLWindow::grabFramebuffer(). More...
 
QVTKOpenGLWindowembeddedOpenGLWindow () const
 Returns the embedded QVTKOpenGLWindow. More...
 
void setFormat (const QSurfaceFormat &fmt)
 Sets the requested surface format. More...
 
QSurfaceFormat format () const
 Returns the context and surface format used by this widget and its toplevel window. More...
 
void SetRenderWindow (vtkGenericOpenGLRenderWindow *win)
 
void SetRenderWindow (vtkRenderWindow *win)
 
vtkRenderWindowGetRenderWindow ()
 These methods have be deprecated to fix naming style. More...
 
QVTKInteractorGetInteractor ()
 
QVTKInteractorAdapterGetInteractorAdapter ()
 
void setQVTKCursor (const QCursor &cursor)
 
void setDefaultQVTKCursor (const QCursor &cursor)
 

Static Public Member Functions

static QSurfaceFormat defaultFormat (bool stereo_capable=false)
 Returns a QSurfaceFormat suitable for surfaces that intend to be used for VTK rendering. More...
 

Protected Member Functions

void resizeEvent (QResizeEvent *evt) override
 
void paintEvent (QPaintEvent *evt) override
 

Detailed Description

QWidget for displaying a vtkRenderWindow in a Qt Application.

QVTKOpenGLWidget simplifies using a QVTKOpenGLWindow as a widget in Qt application so it can be embedded in a layout rather than being a top-level window. QVTKOpenGLWindow has all the limitations posed by Qt with QWidget::createWindowContainer hence developers are advised to refer to Qt docs for more details.

In general QVTKOpenGLNativeWidget may be a better choice, however QVTKOpenGLWindow-based QVTKOpenGLWidget may be better choice for applications requiring quad-buffer stereo.

Due to Qt limitations, QVTKOpenGLWidget does not support being a native widget. But native widget are sometimes mandatory, for example within QScrollArea and QMDIArea, so the QVTKOpenGLNativeWidget should be used when in needs of VTK rendering in the context of Qt native widget.

If a QVTKOpenGLWidget is used in a QScrollArea or in a QMDIArea, it will force it to be native and this is NOT supported.

Unlike QVTKOpenGLNativeWidget, QVTKOpenGLWidget does not require that the default surface format for the application be changed. One can simply specify the needed QSurfaceFormat for the specific QVTKOpenGLWidget instance by calling QVTKOpenGLWidget::setFormat before the widget is initialized.

See also
QVTKOpenGLWindow QVTKOpenGLNativeWidget

Definition at line 64 of file QVTKOpenGLWidget.h.

Constructor & Destructor Documentation

◆ QVTKOpenGLWidget() [1/4]

QVTKOpenGLWidget::QVTKOpenGLWidget ( QWidget *  parent = nullptr,
Qt::WindowFlags  f = Qt::WindowFlags() 
)

◆ QVTKOpenGLWidget() [2/4]

QVTKOpenGLWidget::QVTKOpenGLWidget ( QOpenGLContext *  shareContext,
QWidget *  parent = nullptr,
Qt::WindowFlags  f = Qt::WindowFlags() 
)

◆ QVTKOpenGLWidget() [3/4]

QVTKOpenGLWidget::QVTKOpenGLWidget ( vtkGenericOpenGLRenderWindow w,
QWidget *  parent = nullptr,
Qt::WindowFlags  f = Qt::WindowFlags() 
)

◆ QVTKOpenGLWidget() [4/4]

QVTKOpenGLWidget::QVTKOpenGLWidget ( vtkGenericOpenGLRenderWindow w,
QOpenGLContext *  shareContext,
QWidget *  parent = nullptr,
Qt::WindowFlags  f = Qt::WindowFlags() 
)

◆ ~QVTKOpenGLWidget()

QVTKOpenGLWidget::~QVTKOpenGLWidget ( )
override

Member Function Documentation

◆ setRenderWindow() [1/2]

void QVTKOpenGLWidget::setRenderWindow ( vtkGenericOpenGLRenderWindow win)
inline

Set a render window to use.

It a render window was already set, it will be finalized and all of its OpenGL resource released. If the win is non-null and it has no interactor set, then a QVTKInteractor instance will be created as set on the render window as the interactor.

Definition at line 83 of file QVTKOpenGLWidget.h.

◆ setRenderWindow() [2/2]

void QVTKOpenGLWidget::setRenderWindow ( vtkRenderWindow win)
inline

Definition at line 87 of file QVTKOpenGLWidget.h.

◆ renderWindow()

vtkRenderWindow* QVTKOpenGLWidget::renderWindow ( ) const
inline

Returns the render window that is being shown in this widget.

Definition at line 93 of file QVTKOpenGLWidget.h.

◆ interactor()

QVTKInteractor* QVTKOpenGLWidget::interactor ( ) const
inline

Get the QVTKInteractor that was either created by default or set by the user.

Definition at line 98 of file QVTKOpenGLWidget.h.

◆ defaultFormat()

static QSurfaceFormat QVTKOpenGLWidget::defaultFormat ( bool  stereo_capable = false)
inlinestatic

Returns a QSurfaceFormat suitable for surfaces that intend to be used for VTK rendering.

If your applications plans on using QVTKOpenGLNativeWidget, then this format (or similar) must be set as the default format on QSurfaceFormat before any widgets are created.

Note this returns a QSurfaceFormat required to support the OpenGL rendering capabilities in a vtkRenderWindow. Whether those features, e.g. multi sampling, is actually used for rendering is determined by values specified on the vtkRenderWindow instance itself through appropriate API.

Passing stereo_capable=true is same as calling QSurfaceFormat::setStereo(true). This is necessary if you want to use quad-buffer based stereo in your application.

Refer to Qt docs for QOpenGLWidget and QOpenGLWindow for appropriate locations in your application where to the format may be provided e.g. either on the instance of QOpenGLWindow or QOpenGLWidget subclasses or as default format for the application using QSurfaceFormat::setDefaultFormat().

Definition at line 103 of file QVTKOpenGLWidget.h.

◆ setEnableHiDPI()

void QVTKOpenGLWidget::setEnableHiDPI ( bool  enable)
inline

Enable or disable support for HiDPI displays.

When enabled, this enabled DPI scaling i.e. vtkWindow::SetDPI will be called with a DPI value scaled by the device pixel ratio every time the widget is resized. The unscaled DPI value can be specified by using setUnscaledDPI.

Definition at line 111 of file QVTKOpenGLWidget.h.

◆ enableHiDPI()

bool QVTKOpenGLWidget::enableHiDPI ( ) const
inline

Definition at line 112 of file QVTKOpenGLWidget.h.

◆ setUnscaledDPI()

void QVTKOpenGLWidget::setUnscaledDPI ( int  dpi)
inline

Set/Get unscaled DPI value.

Defaults to 72, which is also the default value in vtkWindow.

Definition at line 119 of file QVTKOpenGLWidget.h.

◆ unscaledDPI()

int QVTKOpenGLWidget::unscaledDPI ( ) const
inline

Definition at line 120 of file QVTKOpenGLWidget.h.

◆ setDefaultCursor()

void QVTKOpenGLWidget::setDefaultCursor ( const QCursor &  cursor)
inline

Set/get the default cursor to use for this widget.

Definition at line 127 of file QVTKOpenGLWidget.h.

◆ defaultCursor()

const QCursor& QVTKOpenGLWidget::defaultCursor ( ) const
inline

Definition at line 128 of file QVTKOpenGLWidget.h.

◆ isValid()

bool QVTKOpenGLWidget::isValid ( )
inline

Returns true if the internal QOpenGLWindow's is valid, i.e.

if OpenGL resources, like the context, have been successfully initialized.

Definition at line 135 of file QVTKOpenGLWidget.h.

◆ grabFramebuffer()

QImage QVTKOpenGLWidget::grabFramebuffer ( )

Expose internal QVTKOpenGLWindow::grabFramebuffer().

Renders and returns a 32-bit RGB image of the framebuffer.

◆ embeddedOpenGLWindow()

QVTKOpenGLWindow* QVTKOpenGLWidget::embeddedOpenGLWindow ( ) const
inline

Returns the embedded QVTKOpenGLWindow.

Definition at line 146 of file QVTKOpenGLWidget.h.

◆ setFormat()

void QVTKOpenGLWidget::setFormat ( const QSurfaceFormat &  fmt)
inline

Sets the requested surface format.

When the format is not explicitly set via this function, the format returned by QSurfaceFormat::defaultFormat() will be used. This means that when having multiple OpenGL widgets, individual calls to this function can be replaced by one single call to QSurfaceFormat::setDefaultFormat() before creating the first widget.

Definition at line 157 of file QVTKOpenGLWidget.h.

◆ format()

QSurfaceFormat QVTKOpenGLWidget::format ( ) const
inline

Returns the context and surface format used by this widget and its toplevel window.

Definition at line 162 of file QVTKOpenGLWidget.h.

◆ SetRenderWindow() [1/2]

void QVTKOpenGLWidget::SetRenderWindow ( vtkGenericOpenGLRenderWindow win)
Deprecated:
in VTK 8.3

◆ SetRenderWindow() [2/2]

void QVTKOpenGLWidget::SetRenderWindow ( vtkRenderWindow win)

◆ GetRenderWindow()

vtkRenderWindow* QVTKOpenGLWidget::GetRenderWindow ( )

These methods have be deprecated to fix naming style.

Since QVTKOpenGLNativeWidget is QObject subclass, we follow Qt naming conventions rather than VTK's.

◆ GetInteractor()

QVTKInteractor* QVTKOpenGLWidget::GetInteractor ( )

◆ GetInteractorAdapter()

QVTKInteractorAdapter* QVTKOpenGLWidget::GetInteractorAdapter ( )
Deprecated:
in VTK 8.3 QVTKInteractorAdapter is an internal helper.

Hence the API was removed.

◆ setQVTKCursor()

void QVTKOpenGLWidget::setQVTKCursor ( const QCursor &  cursor)
Deprecated:
in VTK 8.3.

Simply use QWidget::setCursor API to change cursor.

◆ setDefaultQVTKCursor()

void QVTKOpenGLWidget::setDefaultQVTKCursor ( const QCursor &  cursor)
Deprecated:
in VTK 8.3.

Use setDefaultCursor instead.

◆ resizeEvent()

void QVTKOpenGLWidget::resizeEvent ( QResizeEvent *  evt)
overrideprotected

◆ paintEvent()

void QVTKOpenGLWidget::paintEvent ( QPaintEvent *  evt)
overrideprotected

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