qt - QQuickWidget grab image -


i saving image of qquickwidget several qml children have blank image.

c++ side:

qquickwidget* content.. content->setsource(qurl("qml:/main.qml")); qpixmap *pm = content->grab(qrect(qpoint(0,0),qsize(-1,-1)); pm->save("somefilename.png", 0, 100); 

qml side:

rectangle{  width: 5; height: 5; color: "yellow"; objectname: "rootobj"} 

in qml wish dynamically add children , able show them in image. have tried qquickwindow grabwindow method connection slot , works captures window visible area , need capture whole qml.

i believe not rocket science not getting somewhere. replies!

addendum:

ok, not think issue of before/after rendering since can see qml children before call picture grabber. sorry not being precise.

c++ side:

qquickwidget* content.. content->setsource(qurl("qml:/main.qml")); //do dynamic qml children adding 

after can visually see qml:

qpixmap *pm = content->grab(qrect(qpoint(0,0),qsize(-1,-1)); pm->save(.... 

unless wrong, dont think rendering issue. thank you!

issue mido said. can solve follows.

create class viewer:

viewer.h

class viewer : public qquickview{     q_object public:     explicit viewer(qwindow *parent = 0);     viewer(bool showbar);     virtual ~viewer();     void setmainqmlfile(const qstring file);     void addimportpath(const qstring path);  public slots:     void beforerendering();     void afterrendering() } 

viewer.cpp

#include "viewer.h"  viewer::viewer(qwindow *parent)     : qquickview(parent) {     setwidth(800);     setheight(480);     connect(this, signal(beforerendering()), this, slot(beforerendering()));     connect(this, signal(afterrendering()), this, slot(afterrendering())); }  void viewer::setmainqmlfile(const qstring file) {     setsource(qurl::fromlocalfile(file)); }  void viewer::addimportpath(const qstring path) {     engine()->addimportpath(path); } void viewer::beforerendering() { // }  void viewer::afterrendering() { //grab window   qimage img = this->grabwindow();     img.save(path); //or code } 

main.cpp

viewer *viewer = new viewer; // /// // viewer->setmainqmlfile(qstringliteral("qml/main.qml")); viewer->show(); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -