Can I be notified when a Item has finished repaint

2020-04-17 06:29发布

I'm making a snapshot (via a ShaderEffectSource with live: false) of an Item, but I'm sometimes (1 cases in 200) getting a blank snapshot. I'm making the snapshot based on a signal like this:

Image {
    onStatusChanged: {
        if (status == Image.Ready) {
            snapshotter.makeSnapshot();
        }
    }
}

This is just as an overall context. I won't post a testcase for now because it's a big app and I haven't yet isolated a testcase. That might be material for a future question.

So I'm not asking "where's the bug in my code" yet. Instead I have a simple question that I think may help me fix the bug:

Can I be notified when a Item has finished repainting?

Rationale: Maybe when I get status == Image.Ready, the Image has merely loaded and not yet painted the loaded data into the offscreen surface. So if my desired signal exists, I could hook onto it instead of hooking onto Image.statusChanged.

Note: I could implement my own NotifyingImage component that works like Image but additionally exposes a repainted signal. But I'd like to know if there's a built-in way.

Related question: "Get notified when QQuickItem will need updating". But there the asker is satisfied with knowing when the item data is updated, and I'm asking about a repainted signal, which is something that happens later than what he's asking for.

1条回答
叛逆
2楼-- · 2020-04-17 07:14

As far as I know a Window is always renderd as a whole. So you might use the Window's afterRendering signal.

The downside: It will be triggered, when ever anything in the window has changed. But combined with the (status == Image.Ready) it might work for you.

EDIT:
In a blog post, announcing the release of Qt5.8 the Qt Companies CTO wrote:

In addition, the scene graph now supports partial updates to the screen if only a small area of the scenography changed. This brings some larger performance improvements to the Qt Quick 2D renderer.

I don't know the implementation details of the signal afterRendering, so I can't tell whether this is triggered after such a partial update and if so, how to tell, whether that partial update concerned that part, you are interested in.

查看更多
登录 后发表回答