QGraphicSscene Pop Ups一秒钟就消失了

时间:2012-12-16 19:17:27

标签: qt qt4 qgraphicsscene

我在mainWindow的构造函数中有我所有的代码。问题是显示器只会弹出一秒而不是消失。任何帮助都感激不尽 。以下是代码。

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
QPixmap kineticPix(":/images/kinetic.png");
QPixmap bgPix(":/images/Time-For-Lunch-2.jpg");

QGraphicsScene scene(-350, -350, 700, 700);
QGraphicsItem *buttonParent = new QGraphicsRectItem;

Button *ellipseButton = new Button(QPixmap(":/images/ellipse.png"), buttonParent);
Button *figure8Button = new Button(QPixmap(":/images/figure8.png"), buttonParent);
Button *randomButton = new Button(QPixmap(":/images/random.png"), buttonParent);
Button *tiledButton = new Button(QPixmap(":/images/tile.png"), buttonParent);
Button *centeredButton = new Button(QPixmap(":/images/centered.png"), buttonParent);

ellipseButton->setPos(-100, -100);
figure8Button->setPos(100, -100);
randomButton->setPos(0, 0);
tiledButton->setPos(-100, 100);
centeredButton->setPos(100, 100);

scene.addItem(buttonParent);
buttonParent->scale(0.75, 0.75);
buttonParent->setPos(200, 200);
buttonParent->setZValue(65);


}

1 个答案:

答案 0 :(得分:1)

您已在堆栈上创建了场景,但未将其分配给成员变量,因此只要控件离开构造函数,它就会被删除。