Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

QGraphicsView/QGraphicsScene Multiple (redundant?) resizeEvent and drawBackground calls during resize

$
0
0
I’m getting to many calls to drawBackground during window resize and I’m trying to understand what is causing this behavior. I’ve created a really short sample program that will reproduce this behavior. What I’m seeing is two resizeEvent and four drawBackground calls for each pixel that the window grows during resize with the mouse. Why is this happening and how can I prevent this? The scene can contain a rather heavy OpenGL scene and 4 repaints for each resize event is causing a really bad lag during window resize. Now I guess I could setup an internal state and ignore the extra repaints, but I would really like to know why this is happening and if there’s a more elegant way of preventing this. I’m using Qt 5.1.1 win32 and I’ve tested on both Win7 and 8 with identical results. #include <QApplication> #include <QGraphicsView> #include <QResizeEvent> #include <QDebug> #include <QGraphicsScene> #include <QGLWidget>   // CMainView class CMainView : public QGraphicsView { public:     CMainView() : QGraphicsView()     {         setWindowTitle(tr("Simple QGraphicsView Test"));     }       ~CMainView() {}   protected:     virtual void resizeEvent(QResizeEvent* event)     {         qDebug() << __FUNCTION__ << "size=" << event->size() << "oldSize=" << event->oldSize();         if (scene())             scene()->setSceneRect(QRect(QPoint(0, 0), event->size()));         QGraphicsView::resizeEvent(event);     } };   // CScene class CScene : public QGraphicsScene { public:     CScene() : QGraphicsScene() {}     ~CScene() {}       virtual void drawBackground(QPainter *painter, const QRectF &rect)     {         Q_UNUSED( painter )         qDebug() << __FUNCTION__ << "rect=" << rect;     } };   // main int main(int argc, char *argv[]) {     QApplication app(argc, argv);       QGLWidget *widget = new QGLWidget(QGLFormat(QGL::SampleBuffers));     widget->makeCurrent();       CScene scene;       CMainView view;     view.setViewport(widget);     view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate);     view.setScene(&scene);     view.show();       return app.exec(); }

Viewing all articles
Browse latest Browse all 13965

Trending Articles