qt 布局

发布时间:2026/8/25 13:47:07
qt 布局 一个简单的垂直布局上面是标题栏下面放置label、button、edit等控件。层级图如下void MainWindow::setupUI(){QWidget* totalRootWidget new QWidget(this);QVBoxLayout* totalVerticalLayout new QVBoxLayout(totalRootWidget);totalVerticalLayout-setContentsMargins(0,0,0,0);totalVerticalLayout-setSpacing(0);createCustomTitleBar();//m_titleBarcreateDown();//m_downtotalVerticalLayout-addWidget(m_titleBar);totalVerticalLayout-addWidget(m_down, 1); //下半部分占据剩余全部窗口空间this-setCentralWidget(totalRootWidget);}void MainWindow::createDown(){// 下半部分容器m_down new QWidget();QVBoxLayout* VerticalLayout new QVBoxLayout(m_down);VerticalLayout-setContentsMargins(8,8,8,8);VerticalLayout-setSpacing(10);VerticalLayout-addWidget(ui-graphicsView, 1);VerticalLayout-addWidget(ui-pB_draw, 0,Qt::AlignCenter);VerticalLayout-addWidget(ui-pB_ts, 0,Qt::AlignCenter);ui-pB_draw-setStyleSheet(background-color: #4CAF50; color: white; font-weight: bold;);ui-pB_ts-setStyleSheet(background-color: #4CAF50; color: white; font-weight: bold;);ui-pB_draw-setFixedWidth(120);ui-pB_ts-setFixedWidth(120);}createCustomTitleBar();在前一篇博文里。例程源代码https://download.csdn.net/download/qq_34492056/93324901?spm1001.2014.3001.5503