是否有可能获得由GridLayout填充的大小

Is it possible to get the size filled by a GridLayout?

本文关键字:填充 GridLayout 有可能 是否      更新时间:2023-10-16

在QtCreator中,我使用一个表单来绘制网格布局。在我的主窗口类中,我向这个网格布局添加了一个QGraphicsScene包装器对象,并使用包装器类通过鼠标点击在场景上绘制点。

我点击的是相对于QGraphicsScene包装器的负位置,这不是我想要的效果,所以我想确保我知道我的QGraphicsScene和网格布局填充的坐标。

如何让网格布局填充大小?我正在做这样的事情…

view = new QGraphicsViewWrapper();
ui->gridLayout->addWidget(view);
QGraphicsViewWrapper::QGraphicsViewWrapper(QWidget *parent) : QGraphicsView(parent)
{
    scene = new QGraphicsScene(50, 50, 350, 350);
    this->setSceneRect(50, 50, 350, 350);
    this->setScene(scene);
    this->setGeometry(QRect(20, 50, 400, 400));
}

我不确定我完全理解你的目的,但你能不这样做吗?

QRect size = ui->gridLayout->geometry();