V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
sarlanori
V2EX  ›  问与答

关于 Qt 布局的问题

  •  
  •   sarlanori · 2021-04-23 19:57:59 +08:00 · 379 次点击
    这是一个创建于 1626 天前的主题,其中的信息可能已经有所发展或是发生改变。

    突然发现是 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;
    }
    
    目前尚无回复
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   1900 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 10:23 · PVG 18:23 · LAX 03:23 · JFK 06:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.