我如何调整大小QVBoxLayout填充表单没有空间

How can i resize QVBoxLayout to fill Form without space?

本文关键字:填充 QVBoxLayout 表单 空间 何调整 调整      更新时间:2023-10-16

如何调整QVBoxLayout来填充表单没有空间?

与空间:http://0000.2.img98.net/out.php/i25106_with-space.png

没有空间:http://0000.2.img98.net/out.php/i25107_without-space.png

你必须设置布局的外边距

的例子:

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QVBoxLayout* l = new QVBoxLayout();
    l->setMargin(0); ///m
    QWidget w; w.setFixedSize(300,300);
    w.setLayout(l);
    l->addWidget(new QPushButton("fd"));
    w.show();    
    return app.exec();
}

您需要调整布局中包含的小部件的大小策略。

例如,如果您希望一个小部件占用布局中所有可用的垂直空间,则将小部件的大小策略设置为Expanding

进入项目文件夹,找到Qt Creator下无法编辑的xml文件。您将发现margin xml标记。根据需要增加或减少该值。xml文件不能在Qt Creator下编辑