关于 Qt 布局的问题

2021-04-23 19:57:59 +08:00
 sarlanori

突然发现是 spacing,哎,结帖!!!

====================================================================

如下图所示:

写了一个简单的布局,却不知为何多出来一块区域,试了很久也不知道这块区域是个啥,有知道的大佬还望指点!

窗体代码:

#include "mainwindow2.h"
#include "ui_mainwindow2.h"
#include <QVBoxLayout>
#include <QTextEdit>

MainWindow2::MainWindow2(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow2)
{
    ui->setupUi(this);

    setAttribute(Qt::WA_StyledBackground);

    ui->statusbar->showMessage("Hello World!");

    QVBoxLayout* mainLayout = new QVBoxLayout;
    mainLayout->setMargin(0);
    mainLayout->setContentsMargins(0, 0, 0, 0);

    QWidget* widget = new QWidget;
    widget->setObjectName("box");
    auto boxLayout = new QHBoxLayout(widget);
    boxLayout->setMargin(0);
    boxLayout->setContentsMargins(0, 0, 0, 0);

    auto textEdit = new QTextEdit;
    textEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    mainLayout->addWidget(widget);
    mainLayout->addWidget(textEdit);

    centralWidget()->setLayout(mainLayout);
}

MainWindow2::~MainWindow2()
{
    delete ui;
}

CSS 代码:

* {
  background-color: lightcoral;
}

#box {
  min-height: 49px;
  max-height: 49px;
  margin: 0px;
  border: 1px solid black;
  background-color: red;
}
379 次点击
所在节点    问与答
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://ex.noerr.eu.org/t/772808

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX