要将QPushButton放置到图形视图上..但是没有显示按钮

Want to place a QPushButton onto a GraphicView... but no button is displayed?

本文关键字:按钮 显示 视图 QPushButton 图形 要将      更新时间:2023-10-16

想要将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()));

将其封装在QGraphicsWidget中。

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

哦!别忘了:

m_button6->show(); 

小部件在默认情况下是隐藏的!