VTK  9.3.1
QVTKOpenGLWindow.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
37 #ifndef QVTKOpenGLWindow_h
38 #define QVTKOpenGLWindow_h
39 
40 #include <QOpenGLWindow>
41 #include <QScopedPointer> // for QScopedPointer.
42 
43 #include "QVTKInteractor.h" // needed for QVTKInteractor
44 #include "vtkGUISupportQtModule.h" // for export macro
45 #include "vtkNew.h" // needed for vtkNew
46 #include "vtkSmartPointer.h" // needed for vtkSmartPointer
47 
48 VTK_ABI_NAMESPACE_BEGIN
49 class QVTKInteractor;
53 
54 class VTKGUISUPPORTQT_EXPORT QVTKOpenGLWindow : public QOpenGLWindow
55 {
56  Q_OBJECT
57  typedef QOpenGLWindow Superclass;
58 
59 public:
61  QOpenGLWindow::UpdateBehavior updateBehavior = NoPartialUpdate, QWindow* parent = nullptr);
62  QVTKOpenGLWindow(QOpenGLContext* shareContext,
63  QOpenGLWindow::UpdateBehavior updateBehavior = NoPartialUpdate, QWindow* parent = nullptr);
65  QOpenGLWindow::UpdateBehavior updateBehavior = NoPartialUpdate, QWindow* parent = nullptr);
66  QVTKOpenGLWindow(vtkGenericOpenGLRenderWindow* renderWindow, QOpenGLContext* shareContext,
67  QOpenGLWindow::UpdateBehavior updateBehavior = NoPartialUpdate, QWindow* parent = nullptr);
68  ~QVTKOpenGLWindow() override;
69 
71 
77  void setRenderWindow(vtkGenericOpenGLRenderWindow* win);
78  void setRenderWindow(vtkRenderWindow* win);
80 
84  vtkRenderWindow* renderWindow() const;
85 
89  QVTKInteractor* interactor() const;
90 
94  static QSurfaceFormat defaultFormat(bool stereo_capable = false);
95 
97 
103  void setEnableHiDPI(bool enable);
104  bool enableHiDPI() const { return this->EnableHiDPI; }
106 
108 
112  void setUnscaledDPI(int);
113  int unscaledDPI() const { return this->UnscaledDPI; }
115 
117 
130  void setCustomDevicePixelRatio(double cdpr);
131  double customDevicePixelRatio() const { return this->CustomDevicePixelRatio; }
132  double effectiveDevicePixelRatio() const;
134 
136 
139  void setDefaultCursor(const QCursor& cursor);
140  const QCursor& defaultCursor() const { return this->DefaultCursor; }
142 
143 Q_SIGNALS:
148  void windowEvent(QEvent* e);
149 
150 protected Q_SLOTS:
156  void cleanupContext();
157 
158  void updateSize();
159 
166 
167 protected: // NOLINT(readability-redundant-access-specifiers)
168  bool event(QEvent* evt) override;
169  void initializeGL() override;
170  void paintGL() override;
171  void resizeGL(int w, int h) override;
172 
174  QScopedPointer<QVTKRenderWindowAdapter> RenderWindowAdapter;
175 
176 private:
177  Q_DISABLE_COPY(QVTKOpenGLWindow);
178  bool EnableHiDPI;
179  int UnscaledDPI;
180  double CustomDevicePixelRatio;
181  QCursor DefaultCursor;
182 };
183 
184 VTK_ABI_NAMESPACE_END
185 #endif
an interactor for QVTKOpenGLNativeWidget (and QVTKWiget).
bool enableHiDPI() const
Enable or disable support for HiDPI displays.
const QCursor & defaultCursor() const
Set/get the default cursor to use for this widget.
platform independent render window
display a vtkGenericOpenGLRenderWindow in a Qt QOpenGLWindow.
QWidget for displaying a vtkRenderWindow in a Qt Application.
vtkSmartPointer< vtkGenericOpenGLRenderWindow > RenderWindow
create a window for renderers to draw into
QScopedPointer< QVTKRenderWindowAdapter > RenderWindowAdapter
double customDevicePixelRatio() const
Set/Get a custom device pixel ratio to use to map Qt sizes to VTK (or OpenGL) sizes.
Helper to manage Qt context and other OpenGL components.
int unscaledDPI() const
Set/Get unscaled DPI value.