ImFusion SDK 4.3
QtDisplayWidget Class Reference

#include <ImFusion/GUI/QtDisplayWidget.h>

Specialization of a QOpenGLWidget that allows for rendering the contents of a Display into a QtWidget-based application. More...

+ Inheritance diagram for QtDisplayWidget:

Detailed Description

Specialization of a QOpenGLWidget that allows for rendering the contents of a Display into a QtWidget-based application.

Warning
Make sure you understand and follow the constraints/expected class invariants regarding the used OpenGL contexts by both the ImFusion SDK and by QOpenGLWidget described below. In any case you must make sure that OpenGL context sharing is enabled between the ImFusion context and the used Qt context!

The underlying QOpenGLWidget will always create its own OpenGL context and expect all rendering happen in there. This complicates integration to some extent because the ImFusion SDK also maintains its own context for the main thread in which it expects the main OpenGL objects to reside and the rendering to happen. Therefore, QtDisplayWidget provides two different RenderModes:

  • UseImFusionContext (recommended as default):
    This mode will conduct the rendering in the main context of the ImFusion SDK and therefore temporarily switch away from the Qt context in paintGL(). This simplifies the initialization of OpenGL resources since you can simply instantiate the Display and all Views in the main thread on that main context.
  • UseQOpenGLWidgetContext:
    This mode will conduct the rendering in the context created internally by the QOpenGLWidget as it is designed/intended by Qt. However, it has the drawback that this context is only created after construction of QtDisplayWidget. Therefore you must create all OpenGL resources used by the Display (i.e. its views) only in initializeGL() or in the signalGLContextInitialized callback.

Either way, you must make sure that OpenGL context sharing is enabled between the ImFusion context and the Qt context(s). We recommend the following approach for this:

// enable GL context sharing across all contexts managed by Qt
QGuiApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
QSurfaceFormat::setDefaultFormat(...); // use a format that is compatible with `glCreateInfo` below
QApplication app(argc, argv);
[...]
// initialize the ImFusion SDK with the shared OpenGL context from above
Framework::InitConfig sdkInitConfig;
sdkInitConfig.glContext = std::make_unique<GlContextQt>(0, 0, false, QOpenGLContext::globalShareContext());
Framekwork::init(std::move(sdkInitConfig));
T make_unique(T... args)
Record to configure the initialization of the ImFusion SDK.
Definition Framework.h:35
std::unique_ptr< GL::Context > glContext
Optional OpenGL context to use as main context for the framework.
Definition Framework.h:60

Once the context sharing is configured correctly, the creation of QtDisplayWidget is straight-forward:

// create and configure the Display
[...]
// create the QtDisplayWidget wrapper and add it to your window:
myQLayout->addWidget(displayQt);
Basic version of a display surface hosting a set of Views, rendering them, and distributing input eve...
Definition Display.h:66
Specialization of a QOpenGLWidget that allows for rendering the contents of a Display into a QtWidget...
Definition QtDisplayWidget.h:69
Display & display()
Returns the Display shown by this widget.
Definition QtDisplayWrapperBase.h:30
See also
QtDisplayWindow

Public Types

enum class  RenderMode { UseImFusionContext , UseQOpenGLWidgetContext }
 Enumeration to define in which OpenGL context to conduct the rendering of the display (see class docstring for details). More...
 

Public Member Functions

 QtDisplayWidget (Display &display, QWidget *parent=nullptr, RenderMode renderContext=RenderMode::UseImFusionContext)
 Create a new QtDisplayWidget showing the given display.
 
bool event (QEvent *event) override
 
bool eventFilter (QObject *obj, QEvent *event) override
 
QPointF mapToGlobal (const QPointF &pos) const final override
 Implementations shall forward to Qt's mapToGlobal() function of the wrapper class.
 
- Public Member Functions inherited from QtDisplayWrapperBase
 QtDisplayWrapperBase (Display &display)
 Constructor will subscribe to the Display::signalUpdateRequested signal.
 
Displaydisplay ()
 Returns the Display shown by this widget.
 
QPointF mapFromOpenGL (const vec2 &point) const
 Converts point from ImFusion::GUI's bottom-left-origin coordinates to Qt's top-left-origin coordinates.
 
vec2 mapToOpenGL (const QPointF &point) const
 Converts point from Qt's top-left-origin coordinates to ImFusion::GUI's bottom-left-origin coordinates.
 
- Public Member Functions inherited from SignalReceiver
 SignalReceiver ()=default
 Default constructor.
 
 SignalReceiver (const SignalReceiver &other)
 Copy constructor, does not copy any existing signal connections from other.
 
SignalReceiveroperator= (SignalReceiver rhs)
 Assignment operator, disconnects all existing connections, does not copy any existing signal connections from rhs.
 
virtual ~SignalReceiver ()
 Virtual destructor disconnects from all connected signals.
 

Public Attributes

Signal signalGLContextInitialized
 Signal emitted during initializeGL() to allow for the initialization of GL resources without subclassing.
 

Protected Member Functions

void initializeGL () override
 
void resizeGL (int w, int h) override
 
void paintGL () override
 
void onDisplayUpdateRequested () final override
 Implementations shall make Qt rerender the display.
 
double getDevicePixelRatio () const final override
 Return the device pixel ratio of the screen the display is shown on.
 
int getHeight () const final override
 Return the height of the display wrapper in pixels.
 
void setCursor (const QCursor &cursor) final override
 Implementations shall forward to Qt's setCursor() function of the wrapper class.
 
- Protected Member Functions inherited from QtDisplayWrapperBase
bool handleInputEvent (QEvent *event)
 
- Protected Member Functions inherited from SignalReceiver
void disconnectAll ()
 Disconnects all existing connections.
 

Additional Inherited Members

- Protected Attributes inherited from QtDisplayWrapperBase
Displaym_display
 

Member Enumeration Documentation

◆ RenderMode

enum class RenderMode
strong

Enumeration to define in which OpenGL context to conduct the rendering of the display (see class docstring for details).

Enumerator
UseImFusionContext 

Perform rendering in the ImFusion main context.

UseQOpenGLWidgetContext 

Perform rendering in the context created by the underlying QOpenGLWidget.

Member Function Documentation

◆ mapToGlobal()

QPointF mapToGlobal ( const QPointF & pos) const
finaloverridevirtual

Implementations shall forward to Qt's mapToGlobal() function of the wrapper class.

Implements QtDisplayWrapperBase.

◆ onDisplayUpdateRequested()

void onDisplayUpdateRequested ( )
finaloverrideprotectedvirtual

Implementations shall make Qt rerender the display.

Implements QtDisplayWrapperBase.

◆ getDevicePixelRatio()

double getDevicePixelRatio ( ) const
finaloverrideprotectedvirtual

Return the device pixel ratio of the screen the display is shown on.

Implements QtDisplayWrapperBase.

◆ getHeight()

int getHeight ( ) const
finaloverrideprotectedvirtual

Return the height of the display wrapper in pixels.

Implements QtDisplayWrapperBase.

◆ setCursor()

void setCursor ( const QCursor & cursor)
finaloverrideprotectedvirtual

Implementations shall forward to Qt's setCursor() function of the wrapper class.

Implements QtDisplayWrapperBase.


The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close