How to trigger a QQuickFramebufferObject repaint?
-
I am subclassing
QQuickFramebufferObjectandQQuickFramebufferObject::Rendererto embed an OpenGL canvas in my application. I am callingrender()to queue a repaint, but that isn't working.
Instead, the canvas is only being painted briefly when it is resized, and then goes back to white. Callingrender()does nothing.Here is my
QQuickFramebufferObjectimplementation:ApplicationCanvas::Renderer::Renderer(const ApplicationCanvas *app_canvas) : m_app_canvas(app_canvas) { QObject::connect(m_app_canvas, &ApplicationCanvas::onDrawQueued, [=]() { render(); }); // render() internally calls draw_to_screen() }; void ApplicationCanvas::Renderer::draw_to_screen(SkCanvas* canvas) { canvas->drawColor(SK_ColorBLACK); // does not work for (auto& viewlayer : m_viewlayer_list) { viewlayer->draw_to_screen(canvas); }; // 'Flushing' is what actually renders this frame and shows it to screen canvas->flush(); }; void ApplicationCanvas::keyPressEvent(QKeyEvent *event) { ... emit onDrawQueued(); }; -
update()should be called on your QQuickFBO, not its renderer.Change all your
emit onDrawQueued();to justupdate(); -
Hi and welcome to devnet,
Did you already took a look at the QQuickWidget - QQuickView Comparison Example ?
It shows a usage example of this class.
Hope it helps
-
Thanks! I didn't know an example existed. I read how it works.
Still, the example uses
update()to trigger a repaint. I am using that too. And in my case it does not work and I don't know why.I am subclassing
QQuickFramebufferObject::Renderertwice, I assume it has something to do with this?QQuickFramebufferObject::Renderer->SkiaRenderer->ApplicationCanvas::RendererFull source code: https://gitlab.com/advanced-effects/Advanced-Effects/-/blob/implement-canvas-objects/src/projectscene/view/canvas/application_canvas.cpp?ref_type=heads
Here is the full file:
-
Here's a video demonstration of the issue: https://youtu.be/ojqcShBNmcI
When it's WHITE, it's NOT rendering. When it's BLACK, it IS rendering. -
update()should be called on your QQuickFBO, not its renderer.Change all your
emit onDrawQueued();to justupdate(); -
I don't know why I though
update()was a method of theFBO::Renderer. I changed it now, and I'm having the same issue.Image gets temporarily rendered when resizing the widget, and then goes back to blank.
EDIT: Oh, actually, it was my own fault. Was calling
canvas->flush()which deletes the canvas after drawing. :facepalm: -
K kaixoo has marked this topic as solved