The code below loads an image using QLabel. The code uses: myLabel.setMask(pixmap.mask()); and it works as it should. The problem comes when I try and load an 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 this code I am attempting to the same as above but using QGraphicsScene. The pixmap is loaded properly, after that I am not sure why the program is not working properly. Is it because there is no setMask() operation? Or is there an operation missing that is needed to make the 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(); }
Asked
Active
Viewed 452 times
0

Aborg
- 11
- 2
-
use scene->addPixmap() and add your pixmap directly – mostafaTmj Aug 24 '16 at 03:03
-
What do you mean by "the program is not working properly"? Do you see the image at all? The code shown works as expected for me. – G.M. Aug 24 '16 at 08:04
-
Works for me too. – Wiki Wang Aug 24 '16 at 09:10