Having trouble drawing an image in Qt using QGraphicsScene -
the code below loads image using qlabel. code uses: mylabel.setmask(pixmap.mask()); , works should. problem comes when try , load image using qgraphicsscene.
#include <qapplication> #include <qlabel> #include <qtgui> int main(int argc, char *argv[]) { qapplication app(argc, argv); qlabel mylabel; qpixmap pixmap("/path/tomy/image.jpg"); mylabel.setpixmap(pixmap); mylabel.setmask(pixmap.mask()); mylabel.show(); return app.exec(); }
in code attempting same above using qgraphicsscene. pixmap loaded properly, after not sure why program not working properly. because there no setmask() operation? or there operation missing needed make image visible?
#include <qtglobal> #if qt_version >= 0x050000 #include <qtwidgets> #else #include <qtgui> #endif int main(int argc, char *argv[]) { qapplication a(argc, argv); qpixmap pixmap("/path/tomy/image.jpg"); qgraphicspixmapitem item( pixmap); qgraphicsscene* scene = new qgraphicsscene; scene->additem(&item); qgraphicsview view(scene); view.show(); return a.exec(); }
Comments
Post a Comment