summaryrefslogtreecommitdiffstats
path: root/examples/gui
diff options
context:
space:
mode:
Diffstat (limited to 'examples/gui')
-rw-r--r--examples/gui/analogclock/main.cpp4
-rw-r--r--examples/gui/doc/src/openglwindow.qdoc12
-rw-r--r--examples/gui/doc/src/rasterwindow.qdoc15
-rw-r--r--examples/gui/gui.pro4
-rw-r--r--examples/gui/openglwindow/main.cpp4
-rw-r--r--examples/gui/openglwindow/openglwindow.cpp7
-rw-r--r--examples/gui/openglwindow/openglwindow.h5
-rw-r--r--examples/gui/rasterwindow/rasterwindow.cpp10
-rw-r--r--examples/gui/rasterwindow/rasterwindow.h7
9 files changed, 27 insertions, 41 deletions
diff --git a/examples/gui/analogclock/main.cpp b/examples/gui/analogclock/main.cpp
index 29b21410e3..053ccb54b5 100644
--- a/examples/gui/analogclock/main.cpp
+++ b/examples/gui/analogclock/main.cpp
@@ -59,8 +59,8 @@ public:
AnalogClockWindow();
protected:
- void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE;
- void render(QPainter *p) Q_DECL_OVERRIDE;
+ void timerEvent(QTimerEvent *) override;
+ void render(QPainter *p) override;
private:
int m_timerId;
diff --git a/examples/gui/doc/src/openglwindow.qdoc b/examples/gui/doc/src/openglwindow.qdoc
index e93451c9a5..f283c7cfc0 100644
--- a/examples/gui/doc/src/openglwindow.qdoc
+++ b/examples/gui/doc/src/openglwindow.qdoc
@@ -34,6 +34,9 @@
\image openglwindow-example.png Screenshot of the OpenGLWindow example
+ \note This is a low level example of how to use QWindow with OpenGL.
+ In practice you should consider using the higher level QOpenGLWindow class.
+
\section1 OpenGLWindow Super Class
Our OpenGLWindow class acts as an API which is then subclassed to do the
@@ -70,9 +73,8 @@
\snippet openglwindow/openglwindow.cpp 2
- The renderLater() function simply puts an update request event on
- the event loop, which leads to renderNow() being called once the event
- gets processed.
+ The renderLater() function simply calls QWindow::requestUpdate() to schedule
+ an update for when the system is ready to repaint.
We also call renderNow() when we get an expose event. The exposeEvent() is
the notification to the window that its exposure, meaning visibility, on
@@ -109,11 +111,11 @@
\l {http://www.khronos.org/registry/gles/}{Khronos OpenGL ES API Registry}.
If animation has been enabled with OpenGLWindow::setAnimating(true), we
- call renderLater() to put another update request on the event loop.
+ call renderLater() to schedule another update request.
\snippet openglwindow/openglwindow.cpp 4
- Enabling animation also triggers an update request as shown in the
+ Enabling animation also schedules an update request as shown in the
following code snippet.
\snippet openglwindow/openglwindow.cpp 5
diff --git a/examples/gui/doc/src/rasterwindow.qdoc b/examples/gui/doc/src/rasterwindow.qdoc
index 963d09971d..d276925059 100644
--- a/examples/gui/doc/src/rasterwindow.qdoc
+++ b/examples/gui/doc/src/rasterwindow.qdoc
@@ -143,19 +143,16 @@
\snippet rasterwindow/rasterwindow.cpp 6
We went through a few places where the window needed to repainted
- immediately. There are some cases where this is not desierable,
+ immediately. There are some cases where this is not desirable,
but rather let the application return to the event loop and
- later. We acheive this by posting an even to ourself which will
- then be delivered when the application returns to the \l
- QGuiApplication event loop. To avoid posting new requests when one
- is already pending, we store this state in the \c m_update_pending
- variable.
+ schedule the repaint for later. We achieve this by requesting
+ an update, using QWindow::requestUpdate(), which will then be
+ delivered when the system is ready to repaint.
\snippet rasterwindow/rasterwindow.cpp 7
We reimplement the virtual \l QObject::event() function to handle
- the update event we posted to ourselves. When the event comes in
- we reset the pending update flag and call renderNow() to render
- the window right away.
+ the update event. When the event comes in we call renderNow() to
+ render the window right away.
*/
diff --git a/examples/gui/gui.pro b/examples/gui/gui.pro
index 3a63ffb5eb..a4d960d3f5 100644
--- a/examples/gui/gui.pro
+++ b/examples/gui/gui.pro
@@ -1,10 +1,10 @@
requires(qtHaveModule(gui))
TEMPLATE = subdirs
+QT_FOR_CONFIG += gui
CONFIG += no_docs_target
SUBDIRS += analogclock
SUBDIRS += rasterwindow
-contains(QT_CONFIG, opengl(es2)?) {
+qtConfig(opengl): \
SUBDIRS += openglwindow
-}
diff --git a/examples/gui/openglwindow/main.cpp b/examples/gui/openglwindow/main.cpp
index ba56ba39f5..90c93f0d37 100644
--- a/examples/gui/openglwindow/main.cpp
+++ b/examples/gui/openglwindow/main.cpp
@@ -63,8 +63,8 @@ class TriangleWindow : public OpenGLWindow
public:
TriangleWindow();
- void initialize() Q_DECL_OVERRIDE;
- void render() Q_DECL_OVERRIDE;
+ void initialize() override;
+ void render() override;
private:
GLuint m_posAttr;
diff --git a/examples/gui/openglwindow/openglwindow.cpp b/examples/gui/openglwindow/openglwindow.cpp
index d36614f6a0..57a996a876 100644
--- a/examples/gui/openglwindow/openglwindow.cpp
+++ b/examples/gui/openglwindow/openglwindow.cpp
@@ -59,7 +59,6 @@
//! [1]
OpenGLWindow::OpenGLWindow(QWindow *parent)
: QWindow(parent)
- , m_update_pending(false)
, m_animating(false)
, m_context(0)
, m_device(0)
@@ -99,17 +98,13 @@ void OpenGLWindow::render()
//! [3]
void OpenGLWindow::renderLater()
{
- if (!m_update_pending) {
- m_update_pending = true;
- QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest));
- }
+ requestUpdate();
}
bool OpenGLWindow::event(QEvent *event)
{
switch (event->type()) {
case QEvent::UpdateRequest:
- m_update_pending = false;
renderNow();
return true;
default:
diff --git a/examples/gui/openglwindow/openglwindow.h b/examples/gui/openglwindow/openglwindow.h
index 820eaf1b8f..6e6c1d7449 100644
--- a/examples/gui/openglwindow/openglwindow.h
+++ b/examples/gui/openglwindow/openglwindow.h
@@ -77,12 +77,11 @@ public slots:
void renderNow();
protected:
- bool event(QEvent *event) Q_DECL_OVERRIDE;
+ bool event(QEvent *event) override;
- void exposeEvent(QExposeEvent *event) Q_DECL_OVERRIDE;
+ void exposeEvent(QExposeEvent *event) override;
private:
- bool m_update_pending;
bool m_animating;
QOpenGLContext *m_context;
diff --git a/examples/gui/rasterwindow/rasterwindow.cpp b/examples/gui/rasterwindow/rasterwindow.cpp
index eb34bec252..fb717a4c8a 100644
--- a/examples/gui/rasterwindow/rasterwindow.cpp
+++ b/examples/gui/rasterwindow/rasterwindow.cpp
@@ -53,7 +53,6 @@
//! [1]
RasterWindow::RasterWindow(QWindow *parent)
: QWindow(parent)
- , m_update_pending(false)
{
create();
m_backingStore = new QBackingStore(this);
@@ -68,7 +67,6 @@ RasterWindow::RasterWindow(QWindow *parent)
bool RasterWindow::event(QEvent *event)
{
if (event->type() == QEvent::UpdateRequest) {
- m_update_pending = false;
renderNow();
return true;
}
@@ -79,10 +77,7 @@ bool RasterWindow::event(QEvent *event)
//! [6]
void RasterWindow::renderLater()
{
- if (!m_update_pending) {
- m_update_pending = true;
- QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest));
- }
+ requestUpdate();
}
//! [6]
@@ -99,9 +94,8 @@ void RasterWindow::resizeEvent(QResizeEvent *resizeEvent)
//! [2]
void RasterWindow::exposeEvent(QExposeEvent *)
{
- if (isExposed()) {
+ if (isExposed())
renderNow();
- }
}
//! [2]
diff --git a/examples/gui/rasterwindow/rasterwindow.h b/examples/gui/rasterwindow/rasterwindow.h
index f03975a808..2ccecbf704 100644
--- a/examples/gui/rasterwindow/rasterwindow.h
+++ b/examples/gui/rasterwindow/rasterwindow.h
@@ -67,14 +67,13 @@ public slots:
void renderNow();
protected:
- bool event(QEvent *event) Q_DECL_OVERRIDE;
+ bool event(QEvent *event) override;
- void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
- void exposeEvent(QExposeEvent *event) Q_DECL_OVERRIDE;
+ void resizeEvent(QResizeEvent *event) override;
+ void exposeEvent(QExposeEvent *event) override;
private:
QBackingStore *m_backingStore;
- bool m_update_pending;
};
//! [1]
#endif // RASTERWINDOW_H