V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
sarlanori
V2EX  ›  问与答

关于 Qt 布局的问题

  •  
  •   sarlanori · Apr 23, 2021 · 530 views
    This topic created in 1831 days ago, the information mentioned may be changed or developed.

    突然发现是 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;
    }
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1045 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 18:51 · PVG 02:51 · LAX 11:51 · JFK 14:51
    ♥ Do have faith in what you're doing.