想要将QPushButton放到GraphicView上......但是没有显示按钮?

时间:2013-08-08 19:15:30

标签: c++ qt

想要将QPushButton放置在GraphicView上......但是没有显示按钮?

我正在为每个情节创建一个新窗口。在每个情节中,我想放置一些功能按钮。我不知道是否应该把视图放在另一种窗口上......如果是这样的话? THX

        QGraphicsScene *scene = new QGraphicsScene();

        QPixmap image;
        image.load(fileInfo.filePath(), 0);
        scene->addPixmap(image);
        scene->setSceneRect(image.rect());

        QGraphicsView *view = new QGraphicsView();
        view->setScene(scene);
        view->setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "My Plot"));
        view->resize(1000, 1000);
        view->show();

        QPushButton *m_button6 = new QPushButton("ok", view);
        m_button6->setGeometry(QRect(QPoint(50, 50), QSize(50, 50)));
        connect(m_button6, SIGNAL(released()), this, SLOT(handleButton5()));

1 个答案:

答案 0 :(得分:1)

将它包装在QGraphicsWidget周围。

QGraphicsWidget *pBtn = scene->addWidget(m_button6);  
scene->addItem(pBtn)

哦!不要忘记:

m_button6->show(); 

默认情况下隐藏小部件!