Is there any possible way to make grabToImage()
buffer different from what's displayed in GUI? I'm using ChartView
without legend in GUI and want to export it to PNG
with legend. So I try:
chartView.legend.visible = true
chartView.update()
chartView.grabToImage(function(result) {
console.log("grabbed")
var path = filename.toString().replace(/^(file:\/{2})/,"");
console.log(path + result.saveToFile(path));
chartView.legend.visible = false
update();
});
But both those updates happen only after the control comes out of this function, so I don't get legend drawn in PNG. Also I would like the appearance of legend to be unnoticable to user. Are there any ways to do that in QML?
I am unsure, whether I got you quite right.
My suggestion is, to not grab the
Item
you display, but a copy of it, that you then modify as you like.Copy here does not mean, that you have the same object twice, but that you render it twice by using a
ShaderEffectSource
. Before you grab thisShaderEffectSource
to image, you can add anything you like.In my example I display a simple
Rectangle
with a nice gradient. What I save is the sameRectangle
that is extended by theText
'I am legend'. The user won't see this text apearing in the view at any time.You might optimize the performance by only having the
ShaderEffectSource
active or even created when needed.You might use the
ShaderEffectSource.live
-property to disable updating of it. Then usescheduleUpdate()
to trigger the update.This might look like this: