VTK  9.3.1
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());
117  ~QVTKOpenGLNativeWidget() override;
118 
120 
126  void setRenderWindow(vtkGenericOpenGLRenderWindow* win);
127  void setRenderWindow(vtkRenderWindow* win);
129 
133  vtkRenderWindow* renderWindow() const;
134 
138  QVTKInteractor* interactor() const;
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; }
181  double effectiveDevicePixelRatio() const;
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
QScopedPointer< QVTKRenderWindowAdapter > RenderWindowAdapter
vtkSmartPointer< vtkGenericOpenGLRenderWindow > RenderWindow
bool enableHiDPI() const
Enable or disable support for HiDPI displays.
const QCursor & defaultCursor() const
Set/get the default cursor to use for this widget.
double customDevicePixelRatio() const
Set/Get a custom device pixel ratio to use to map Qt sizes to VTK (or OpenGL) sizes.
an interactor for QVTKOpenGLNativeWidget (and QVTKWiget).
void setCursorCustom(const QCursor &cursor)
Convenience method by symmetry with QVTKOpenGLStereoWidget.
QOpenGLWidget subclass to house a vtkGenericOpenGLRenderWindow in a Qt application.
int unscaledDPI() const
Set/Get unscaled DPI value.
platform independent render window
QCursor cursorCustom() const
Convenience method by symmetry with QVTKOpenGLStereoWidget.
create a window for renderers to draw into
Helper to manage Qt context and other OpenGL components.