VTK  9.2.6
QVTKOpenGLNativeWidget.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: QVTKOpenGLNativeWidget.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
103 #ifndef QVTKOpenGLNativeWidget_h
104 #define QVTKOpenGLNativeWidget_h
105 
106 #include <QOpenGLWidget>
107 #include <QScopedPointer> // for QScopedPointer.
108 
109 #include "QVTKInteractor.h" // needed for QVTKInteractor
110 #include "vtkGUISupportQtModule.h" // for export macro
111 #include "vtkNew.h" // needed for vtkNew
112 #include "vtkSmartPointer.h" // needed for vtkSmartPointer
113 
114 class QVTKInteractor;
118 
119 class VTKGUISUPPORTQT_EXPORT QVTKOpenGLNativeWidget : public QOpenGLWidget
120 {
121  Q_OBJECT
122  typedef QOpenGLWidget Superclass;
123 
124 public:
125  QVTKOpenGLNativeWidget(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
126  QVTKOpenGLNativeWidget(vtkGenericOpenGLRenderWindow* window, QWidget* parent = nullptr,
127  Qt::WindowFlags f = Qt::WindowFlags());
128  ~QVTKOpenGLNativeWidget() override;
129 
131 
137  void setRenderWindow(vtkGenericOpenGLRenderWindow* win);
138  void setRenderWindow(vtkRenderWindow* win);
140 
144  vtkRenderWindow* renderWindow() const;
145 
149  QVTKInteractor* interactor() const;
150 
154  static QSurfaceFormat defaultFormat(bool stereo_capable = false);
155 
157 
163  void setEnableHiDPI(bool enable);
164  bool enableHiDPI() const { return this->EnableHiDPI; }
166 
168 
172  void setUnscaledDPI(int);
173  int unscaledDPI() const { return this->UnscaledDPI; }
175 
177 
190  void setCustomDevicePixelRatio(double cdpr);
191  double customDevicePixelRatio() const { return this->CustomDevicePixelRatio; }
192  double effectiveDevicePixelRatio() const;
194 
196 
199  void setDefaultCursor(const QCursor& cursor);
200  const QCursor& defaultCursor() const { return this->DefaultCursor; }
202 
203 protected Q_SLOTS:
209  virtual void cleanupContext();
210 
211  void updateSize();
212 
213 protected:
214  bool event(QEvent* evt) override;
215  void initializeGL() override;
216  void paintGL() override;
217 
218 protected:
220  QScopedPointer<QVTKRenderWindowAdapter> RenderWindowAdapter;
221 
222 private:
223  Q_DISABLE_COPY(QVTKOpenGLNativeWidget);
224 
225  bool EnableHiDPI;
226  int UnscaledDPI;
227  double CustomDevicePixelRatio;
228  QCursor DefaultCursor;
229 };
230 
231 #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).
QOpenGLWidget subclass to house a vtkGenericOpenGLRenderWindow in a Qt application.
int unscaledDPI() const
Set/Get unscaled DPI value.
platform independent render window
create a window for renderers to draw into
Helper to manage Qt context and other OpenGL components.