QT开发中文网

在graphicsView控件上,放置button

要在 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助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://qt.0voice.com/?id=10364

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?