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

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

#include <QVTKOpenGLWidget.h>

Inherits QWidget.

Signals

void mouseEvent (QMouseEvent *event)
 This signal will be emitted whenever a mouse event occurs within the QVTK window. More...
 
void resized ()
 This signal will be emitted whenever a resize event occurs within the QVTK window. More...
 
void widgetEvent (QEvent *e)
 Forward events to the internal QVTK window. More...
 

Public Member Functions

 QVTKOpenGLWidget (QWidget *parent=Q_NULLPTR, Qt::WindowFlags f=Qt::WindowFlags())
 
 QVTKOpenGLWidget (QOpenGLContext *shareContext, QWidget *parent=Q_NULLPTR, Qt::WindowFlags f=Qt::WindowFlags())
 
 QVTKOpenGLWidget (vtkGenericOpenGLRenderWindow *w, QWidget *parent=Q_NULLPTR, Qt::WindowFlags f=Qt::WindowFlags())
 
 QVTKOpenGLWidget (vtkGenericOpenGLRenderWindow *w, QOpenGLContext *shareContext, QWidget *parent=Q_NULLPTR, Qt::WindowFlags f=Qt::WindowFlags())
 
 ~QVTKOpenGLWidget () override
 
void SetRenderWindow (vtkGenericOpenGLRenderWindow *win)
 Set the VTK render window for the internal QVTKOpenGLWindow. More...
 
void SetRenderWindow (vtkRenderWindow *win)
 
virtual vtkRenderWindowGetRenderWindow ()
 Get the VTK render window from the internal QVTKOpenGLWindow. More...
 
virtual vtkRenderWindowInteractorGetInteractor ()
 Get the VTK render window interactor from the internal QVTKOpenGLWindow. More...
 
virtual QVTKInteractorAdapterGetInteractorAdapter ()
 Get the QEvent to VTK events translator. More...
 
void setFormat (const QSurfaceFormat &format)
 Set the QSurfaceFormat used to create the OpenGL context. More...
 
virtual void setEnableHiDPI (bool enable)
 Enable or disable support for HiDPI displays. More...
 
virtual bool enableHiDPI ()
 
void setQVTKCursor (const QCursor &cursor)
 Set the cursor on this widget. More...
 
virtual bool isValid ()
 Returns true if the internal QOpenGLWindow's is valid, i.e. More...
 
virtual bool testingEvent (QEvent *e)
 Forward events to the internal QVTKOpenGLWindow when events are explicitly sent to the widget. More...
 
QImage grabFramebuffer ()
 Expose internal QVTKOpenGLWindow::grabFramebuffer(). More...
 

Static Public Member Functions

static QSurfaceFormat defaultFormat ()
 Returns a typical QSurfaceFormat suitable for most applications using QVTKOpenGLWidget. More...
 

Protected Member Functions

virtual void resizeEvent (QResizeEvent *event) Q_DECL_OVERRIDE
 
virtual bool event (QEvent *e) Q_DECL_OVERRIDE
 

Protected Attributes

bool EnableHiDPI = true
 

Detailed Description

QWidget for displaying a vtkRenderWindow in a Qt Application.

QVTKOpenGLWidget is a QWidget wrapper around QVTKOpenGLWindow. It holds a pointer to an internal QVTKOpenGLWindow instance in order to display VTK data in a Qt OpenGL context.

It was designed to support quad buffer stereo rendering.

A typical usage for QVTKOpenGLWidget is as follows:

// This must be done before instantiating the app in order to setup the
// right context for our widget.
QSurfaceFormat::setDefaultFormat(QVTKOpenGLWidget::defaultFormat());
QApplication app(argc, argv);
QScopedPointer<QVTKOpenGLWidget> qvtkWidget(new QVTKOpenGLWidget(window));
// You can continue to use `window` as a regular vtkRenderWindow
// including adding renderers, actors etc.
// Show the widget and start the app.
qvtkWidget->show();
return app.exec();

External calls requesting the render window to render might not be safe. Please make sure that QVTKOpenGLWidget::isValid() returns true before making explicit call to vtkGenericOpenGLRenderWindow::Render(). An alternative is to call update() on the widget instance to trigger a render once the context gets validated;

QVTKOpenGLWidget is compatible with Qt version 5.6 and above, but it is mainly tested on Qt 5.9 and above.

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.

See also
QVTKOpenGLWindow QVTKOpenGLNativeWidget

Definition at line 84 of file QVTKOpenGLWidget.h.

Constructor & Destructor Documentation

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

Member Function Documentation

void QVTKOpenGLWidget::SetRenderWindow ( vtkGenericOpenGLRenderWindow win)

Set the VTK render window for the internal QVTKOpenGLWindow.

void QVTKOpenGLWidget::SetRenderWindow ( vtkRenderWindow win)
virtual vtkRenderWindow* QVTKOpenGLWidget::GetRenderWindow ( )
virtual

Get the VTK render window from the internal QVTKOpenGLWindow.

virtual vtkRenderWindowInteractor* QVTKOpenGLWidget::GetInteractor ( )
virtual

Get the VTK render window interactor from the internal QVTKOpenGLWindow.

virtual QVTKInteractorAdapter* QVTKOpenGLWidget::GetInteractorAdapter ( )
virtual

Get the QEvent to VTK events translator.

static QSurfaceFormat QVTKOpenGLWidget::defaultFormat ( )
static

Returns a typical QSurfaceFormat suitable for most applications using QVTKOpenGLWidget.

Note that this is not the QSurfaceFormat that gets used if none is specified. That is set using QSurfaceFormat::setDefaultFormat.

void QVTKOpenGLWidget::setFormat ( const QSurfaceFormat &  format)

Set the QSurfaceFormat used to create the OpenGL context.

virtual void QVTKOpenGLWidget::setEnableHiDPI ( bool  enable)
virtual

Enable or disable support for HiDPI displays.

virtual bool QVTKOpenGLWidget::enableHiDPI ( )
inlinevirtual

Definition at line 136 of file QVTKOpenGLWidget.h.

void QVTKOpenGLWidget::setQVTKCursor ( const QCursor &  cursor)

Set the cursor on this widget.

virtual bool QVTKOpenGLWidget::isValid ( )
virtual

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

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

virtual bool QVTKOpenGLWidget::testingEvent ( QEvent *  e)
virtual

Forward events to the internal QVTKOpenGLWindow when events are explicitly sent to the widget.

This is required due to QTBUG-61836 that prevents the use of the flag Qt::TransparentForMouseInput. This flag indicates that the internal window let events pass through. When this misbehavior gets fixed, events will be forwarded to this widget's event() callback, that will then forward them back to the window.

QImage QVTKOpenGLWidget::grabFramebuffer ( )

Expose internal QVTKOpenGLWindow::grabFramebuffer().

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

void QVTKOpenGLWidget::mouseEvent ( QMouseEvent *  event)
signal

This signal will be emitted whenever a mouse event occurs within the QVTK window.

void QVTKOpenGLWidget::resized ( )
signal

This signal will be emitted whenever a resize event occurs within the QVTK window.

void QVTKOpenGLWidget::widgetEvent ( QEvent *  e)
signal

Forward events to the internal QVTK window.

virtual void QVTKOpenGLWidget::resizeEvent ( QResizeEvent *  event)
protectedvirtual
virtual bool QVTKOpenGLWidget::event ( QEvent *  e)
protectedvirtual

Member Data Documentation

bool QVTKOpenGLWidget::EnableHiDPI = true
protected

Definition at line 191 of file QVTKOpenGLWidget.h.


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