c++ - QGraphicsObject doesn't display QPixmap -
i'm developing simple application on win7 , running on win8. when run on win7 shows pixmap drawn qgraphicsobject
subclass. when copy exe , dll's tablet doesn't show pixmap else same.
another problem when quit application says unexpectedly closed.
here related parts
myimage::myimage(qgraphicsobject *parent) : qgraphicsobject(parent) { pxm = new qpixmap("://images/flower.jpg"); setscale(0.5); } qrectf myimage::boundingrect() const { qrectf rect(0,0,pxm->width(),pxm->height()); return rect; } void myimage::paint( qpainter* painter, const qstyleoptiongraphicsitem* /*option*/, qwidget* /*widget*/ ) { painter->drawpixmap( 0, 0, pxm->width(), pxm->height(), *pxm ); }
and here main function
int main(int argc, char *argv[]) { qapplication app(argc, argv); qgraphicsscene scene; myimage img; scene.additem(&img); qgraphicsview view(&scene); qwidget window; window.setfixedheight(400); window.setfixedwidth(500); window.setsizepolicy(qsizepolicy::fixed,qsizepolicy::fixed); qpushbutton button("quit"); qobject::connect(&button,signal(clicked()),&app,slot(quit())); qvboxlayout layout; layout.addwidget(&view); layout.addwidget(&button); window.setlayout(&layout); window.show(); return app.exec(); }
the problem here you're using jpeg image, isn't native qt. in installation of qt you'll find plugins folder folder called "imageformats". if copy folder of libraries path of executable (assuming windows), should work. similar discussion here.
alternatively, use different image format jpeg.
Comments
Post a Comment