summaryrefslogtreecommitdiffstats
path: root/examples/opengl/paintedwindow/paintedwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/opengl/paintedwindow/paintedwindow.cpp')
-rw-r--r--examples/opengl/paintedwindow/paintedwindow.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/examples/opengl/paintedwindow/paintedwindow.cpp b/examples/opengl/paintedwindow/paintedwindow.cpp
new file mode 100644
index 0000000000..9b27c56914
--- /dev/null
+++ b/examples/opengl/paintedwindow/paintedwindow.cpp
@@ -0,0 +1,53 @@
+#include "paintedwindow.h"
+
+#include <QOpenGLContext>
+#include <QOpenGLPaintDevice>
+#include <QPainter>
+#include <QTimer>
+
+#include <qmath.h>
+
+PaintedWindow::PaintedWindow()
+{
+ QSurfaceFormat format;
+ format.setStencilBufferSize(8);
+ format.setSamples(4);
+
+ setSurfaceType(QWindow::OpenGLSurface);
+ setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
+ setFormat(format);
+
+ create();
+
+ m_context = new QOpenGLContext(this);
+ m_context->setFormat(format);
+ m_context->create();
+}
+
+void PaintedWindow::resizeEvent(QResizeEvent *)
+{
+ paint();
+}
+
+void PaintedWindow::exposeEvent(QExposeEvent *)
+{
+ paint();
+}
+
+void PaintedWindow::paint()
+{
+ m_context->makeCurrent(this);
+
+ QPainterPath path;
+ path.addEllipse(0, 0, width(), height());
+
+ QOpenGLPaintDevice device(size());
+
+ QPainter painter(&device);
+ painter.fillRect(0, 0, width(), height(), Qt::white);
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.fillPath(path, Qt::blue);
+ painter.end();
+
+ m_context->swapBuffers(this);
+}