diff options
author | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2014-12-12 12:59:43 +0100 |
---|---|---|
committer | Kai Koehne <kai.koehne@theqtcompany.com> | 2014-12-18 09:46:23 +0100 |
commit | 6c2da36c22e25e626a9812419332ad379e854133 (patch) | |
tree | 63b70bc1fce47768f262b3793d93338f42bfd79f /tests/auto/widgets | |
parent | b8e71aa8477765008798d4bd7887244cb4cc2db7 (diff) | |
download | qtbase-6c2da36c22e25e626a9812419332ad379e854133.tar.gz |
Prevent continuous painting with viewport QOpenGLWidget
Add the source widget to the texture list (may be null for custom
compositor implementations that add textures not belonging to actual
widgets). This allows us to do proper checks with the
dirtyRenderToTextureWidgets list.
As a result paint events are only sent to a QOpenGLWidget if (1) there
was an update() for it or (2) it was actually marked dirty. (2) was
previously behaving differently: the widget got a paint event when
anything in the window has changed. This is fine for naive animating
OpenGL code but less ideal for QGraphicsView.
Bool properties like stacksOnTop are now stored in a flags value to
prevent future explosion of texture list fields and parameters.
Task-number: QTBUG-43178
Change-Id: I48cbcf93df72ac682c9b5d64982a8b648fe21ef3
Reviewed-by: Jørgen Lind <jorgen.lind@theqtcompany.com>
Reviewed-by: Paul Olav Tvete <paul.tvete@theqtcompany.com>
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r-- | tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp b/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp index d309b0840e..2ac31bfe1b 100644 --- a/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp +++ b/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp @@ -34,6 +34,11 @@ #include <QtWidgets/QOpenGLWidget> #include <QtGui/QOpenGLFunctions> #include <QtGui/QPainter> +#include <QtWidgets/QGraphicsView> +#include <QtWidgets/QGraphicsScene> +#include <QtWidgets/QGraphicsRectItem> +#include <QtWidgets/QVBoxLayout> +#include <QtWidgets/QPushButton> #include <QtTest/QtTest> #include <QSignalSpy> @@ -49,6 +54,7 @@ private slots: void painter(); void reparentToAlreadyCreated(); void reparentToNotYetCreated(); + void asViewport(); }; void tst_QOpenGLWidget::create() @@ -253,6 +259,52 @@ void tst_QOpenGLWidget::reparentToNotYetCreated() QVERIFY(image.pixel(20, 10) == qRgb(0, 0, 255)); } +class CountingGraphicsView : public QGraphicsView +{ +public: + CountingGraphicsView(): m_count(0) { } + int paintCount() const { return m_count; } + void resetPaintCount() { m_count = 0; } + +protected: + void drawForeground(QPainter *, const QRectF &) Q_DECL_OVERRIDE; + int m_count; +}; + +void CountingGraphicsView::drawForeground(QPainter *, const QRectF &) +{ + ++m_count; +} + +void tst_QOpenGLWidget::asViewport() +{ + // Have a QGraphicsView with a QOpenGLWidget as its viewport. + QGraphicsScene scene; + scene.addItem(new QGraphicsRectItem(10, 10, 100, 100)); + CountingGraphicsView *view = new CountingGraphicsView; + view->setScene(&scene); + view->setViewport(new QOpenGLWidget); + QWidget widget; + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(view); + QPushButton *btn = new QPushButton("Test"); + layout->addWidget(btn); + widget.setLayout(layout); + widget.show(); + QTest::qWaitForWindowExposed(&widget); + + QVERIFY(view->paintCount() > 0); + view->resetPaintCount(); + + // And now trigger a repaint on the push button. We must not + // receive paint events for the graphics view. If we do, that's a + // side effect of QOpenGLWidget's special behavior and handling in + // the widget stack. + btn->update(); + qApp->processEvents(); + QVERIFY(view->paintCount() == 0); +} + QTEST_MAIN(tst_QOpenGLWidget) #include "tst_qopenglwidget.moc" |