Qt 如何将带有QPushButtons 50px的QVBoxLayout移到顶部?

Qt 如何将带有QPushButtons 50px的QVBoxLayout移到顶部?,qt,qlayout,qvboxlayout,Qt,Qlayout,Qvboxlayout,如何将带有多个QPushButtons 50px的QVBoxLayout移到顶部 这是我的密码。我尝试了这个->调整大小(),这个->重新绘制(),但它不动 // get current geometry QRect geo = ui->VBoxLayout->geometry(); // apply geometry, but substract 50px from y() to move it to the top ui->VBoxLayout->setGeomet

如何将带有多个QPushButtons 50px的QVBoxLayout移到顶部

这是我的密码。我尝试了这个->调整大小(),这个->重新绘制(),但它不动

// get current geometry
QRect geo = ui->VBoxLayout->geometry();

// apply geometry, but substract 50px from y() to move it to the top
ui->VBoxLayout->setGeometry(
    QRect(geo.x(), geo.y() - 50, geo.width(), geo.height())
);

QVBoxLayout不是可移动的单机版。 解决方案是将QVBoxLayout嵌入到相同大小的QWidget中(ui->VBoxLayout in ui->RightSideWidget)。QWidget可以通过move()移动

作为第一个小部件?
QRect geoWidget = ui->RightSideWidget->geometry();
ui->RightSideWidget->move(geoWidget.x(), geoWidget.y() - 50);