c++ - Qt Update QPixmapItem in QGraphicsScene -
i want have image in main window buttons laid out on top of image. using view, scene , pixmap item when try change pixmap item in slot function, crash.
here example of have:
mainwindow::mainwindow(qwidget *parent) : qmainwindow(parent), ui(new ui::mainwindow) { ui->setupui(this); //scene, view, pixitem , button private variables in header qgraphicsscene *scene = new qgraphicsscene(this); qgraphicsview *view = new qgraphicsview(scene); qgraphicspixmapitem *pixitem = new qgraphicspixmapitem; pixitem->setpixmap(qpixmap(":/img/this.png")); scene->additem(pixitem); qpushbutton *button = new qpushbutton(view); this->connect(button,signal(clicked()),this,slot(slot())); this->setcentralwidget(view); } void mainwindow:slot() { pixitem->setpixmap(qpixmap(":/img/that.png")); }
possible duplicate solution did not work me: qt update pixmap of qgraphicspixmapitem
you have shadowed member variable pixitem
because using
qgraphicspixmapitem *pixitem = new qgraphicspixmapitem;
the pixitem
added scene reference local variable, not member variable. change
pixitem = new qgraphicspixmapitem;
Comments
Post a Comment