PDA

View Full Version : Graphics View basic usage help



freelyfly
5th July 2012, 01:32
Hello, I am trying to build a GUI for my OpenCV program. I would like to use Graphic View to display the processed image from OpenCV.

However, as a Qt newbie I am stuck with the basic usage of displaying a pixmap (which I planned to use for my OpenCV images). Following is the the C++ code I wrote to display a 100x100 pixel red pixmap. "gui" is the UI created with Designer (which contains a Qgraphicsview widget). The code compiles but when it runs the pixmap is not shown.

Please tell me what is wrong my code and how should I correct it. Thank you for your help!



gui.setupUi(this);
QGraphicsScene GCSscene;
QPixmap* GCSpixmap = new QPixmap(100,100);
GCSpixmap->fill(QColor(255,0,0));
QGraphicsPixmapItem* GCSpixmapitem = GCSscene.addPixmap(*GCSpixmap);
(gui.graphicsView)->setScene(&GCSscene);
(gui.graphicsView)->show();

wysota
5th July 2012, 09:00
You are probably using a local variable that goes out of scope and gets destroyed.