要在 QGraphicsView 控件上放置一个按钮,可以使用 QGraphicsScene 和 QGraphicsProxyWidget。
首先,在需要放置按钮的地方创建 QGraphicsScene 对象:
QGraphicsScene* scene = new QGraphicsScene(this);
接下来,创建 QPushButton 对象并设置其属性:
QPushButton* deleteButton = new QPushButton("X");
deleteButton->setFixedSize(30, 20);
然后,创建 QGraphicsProxyWidget,并将按钮添加到其中:
QGraphicsProxyWidget* proxy = scene->addWidget(deleteButton);
最后,将场景设置给 QGraphicsView 控件显示出来:
ui->graphicsView->setScene(scene);
这样就能在 QGraphicsView 上显示一个按钮了。你可以根据需要调整按钮的大小和位置。
内容由零声教学AI助手提供,问题来源于学员提问