VTK  9.3.20240329
QVTKOpenGLNativeWidget.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
91 #ifndef QVTKOpenGLNativeWidget_h
92 #define QVTKOpenGLNativeWidget_h
93 
94 #include <QOpenGLWidget>
95 #include <QScopedPointer> // for QScopedPointer.
96 
97 #include "QVTKInteractor.h" // needed for QVTKInteractor
98 #include "vtkGUISupportQtModule.h" // for export macro
99 #include "vtkNew.h" // needed for vtkNew
100 #include "vtkSmartPointer.h" // needed for vtkSmartPointer
101 
102 VTK_ABI_NAMESPACE_BEGIN
103 class QVTKInteractor;
107 
108 class VTKGUISUPPORTQT_EXPORT QVTKOpenGLNativeWidget : public QOpenGLWidget
109 {
110  Q_OBJECT
111  typedef QOpenGLWidget Superclass;
112 
113 public:
114  QVTKOpenGLNativeWidget(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
115  QVTKOpenGLNativeWidget(vtkGenericOpenGLRenderWindow* window, QWidget* parent = nullptr,
116  Qt::WindowFlags f = Qt::WindowFlags());
118 
120 
129 
134 
139 
143  static QSurfaceFormat defaultFormat(bool stereo_capable = false);
144 
146 
152  void setEnableHiDPI(bool enable);
153  bool enableHiDPI() const { return this->EnableHiDPI; }
155 
157 
161  void setUnscaledDPI(int);
162  int unscaledDPI() const { return this->UnscaledDPI; }
164 
166 
179  void setCustomDevicePixelRatio(double cdpr);
180  double customDevicePixelRatio() const { return this->CustomDevicePixelRatio; }
183 
185 
188  void setDefaultCursor(const QCursor& cursor);
189  const QCursor& defaultCursor() const { return this->DefaultCursor; }
191 
193 
197  void setCursorCustom(const QCursor& cursor) { this->setCursor(cursor); }
198  QCursor cursorCustom() const { return this->cursor(); }
200 
201 protected Q_SLOTS:
207  virtual void cleanupContext();
208 
209  void updateSize();
210 
211 protected: // NOLINT(readability-redundant-access-specifiers)
212  bool event(QEvent* evt) override;
213  void initializeGL() override;
214  void paintGL() override;
215 
217  QScopedPointer<QVTKRenderWindowAdapter> RenderWindowAdapter;
218 
219 private:
220  Q_DISABLE_COPY(QVTKOpenGLNativeWidget);
221 
222  bool EnableHiDPI;
223  int UnscaledDPI;
224  double CustomDevicePixelRatio;
225  QCursor DefaultCursor;
226 };
227 
228 VTK_ABI_NAMESPACE_END
229 #endif
an interactor for QVTKOpenGLNativeWidget (and QVTKWiget).
QOpenGLWidget subclass to house a vtkGenericOpenGLRenderWindow in a Qt application.
QVTKInteractor * interactor() const
Get the QVTKInteractor that was either created by default or set by the user.
bool enableHiDPI() const
Enable or disable support for HiDPI displays.
virtual void cleanupContext()
Called as a response to QOpenGLContext::aboutToBeDestroyed.
int unscaledDPI() const
Set/Get unscaled DPI value.
void setCustomDevicePixelRatio(double cdpr)
Set/Get a custom device pixel ratio to use to map Qt sizes to VTK (or OpenGL) sizes.
bool event(QEvent *evt) override
~QVTKOpenGLNativeWidget() override
void initializeGL() override
void setEnableHiDPI(bool enable)
Enable or disable support for HiDPI displays.
QCursor cursorCustom() const
Convenience method by symmetry with QVTKOpenGLStereoWidget.
QScopedPointer< QVTKRenderWindowAdapter > RenderWindowAdapter
vtkSmartPointer< vtkGenericOpenGLRenderWindow > RenderWindow
void setRenderWindow(vtkGenericOpenGLRenderWindow *win)
Set a render window to use.
double effectiveDevicePixelRatio() const
Set/Get a custom device pixel ratio to use to map Qt sizes to VTK (or OpenGL) sizes.
void setUnscaledDPI(int)
Set/Get unscaled DPI value.
const QCursor & defaultCursor() const
Set/get the default cursor to use for this widget.
void setCursorCustom(const QCursor &cursor)
Convenience method by symmetry with QVTKOpenGLStereoWidget.
QVTKOpenGLNativeWidget(vtkGenericOpenGLRenderWindow *window, QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
void setDefaultCursor(const QCursor &cursor)
Set/get the default cursor to use for this widget.
static QSurfaceFormat defaultFormat(bool stereo_capable=false)
Returns a QSurfaceFormat suitable for surfaces that intend to be used for VTK rendering.
vtkRenderWindow * renderWindow() const
Returns the render window that is being shown in this widget.
double customDevicePixelRatio() const
Set/Get a custom device pixel ratio to use to map Qt sizes to VTK (or OpenGL) sizes.
void paintGL() override
QVTKOpenGLNativeWidget(QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
void setRenderWindow(vtkRenderWindow *win)
Set a render window to use.
Helper to manage Qt context and other OpenGL components.
platform independent render window
create a window for renderers to draw into