1、对组件底部加弹簧;

feature/struct-menu-20241023
simonyan 2 weeks ago
parent 8c937cad48
commit 4f400bd1c0

@ -1,4 +1,4 @@
#include "CUI.h" #include "CUI.h"
#include<CUIConfig.h> #include<CUIConfig.h>
#include<CUIWidget.h> #include<CUIWidget.h>
@ -20,7 +20,6 @@
CUI::CUI(QWidget *parent, CUIConfig *conf): QWidget(parent) CUI::CUI(QWidget *parent, CUIConfig *conf): QWidget(parent)
{ {
this->conf = conf; this->conf = conf;
// this->conf->printConfig();
qDebug() << "----------------------"; qDebug() << "----------------------";
buildUI(); buildUI();
} }
@ -58,10 +57,12 @@ void CUI::buildUI()
if (widget) { if (widget) {
qDebug() << "----------- ui widget is not null"; qDebug() << "----------- ui widget is not null";
QVBoxLayout *layout = new QVBoxLayout; QVBoxLayout *layout = new QVBoxLayout;
layout->setSpacing(0);
layout->setMargin(0);
layout->addWidget(widget); layout->addWidget(widget);
this->setLayout(layout); this->setLayout(layout);
// QSpacerItem* spacer = new QSpacerItem(5000,5000,QSizePolicy::Maximum,QSizePolicy::Maximum); // QSpacerItem *verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
// layout->addItem(spacer); // layout->addSpacerItem(verticalSpacer);
} else { } else {
qDebug() << "----------- ui widget is null"; qDebug() << "----------- ui widget is null";

@ -1,4 +1,4 @@
#include "CUIWidget.h" #include "CUIWidget.h"
#include "CUIConfig.h" #include "CUIConfig.h"
#include "QVBoxLayout" #include "QVBoxLayout"
#include <QLayout> #include <QLayout>
@ -29,6 +29,11 @@ void CUIWidget::iniUI(QVector<CUI*> &subCUI)
subCUI.push_back(tmp); subCUI.push_back(tmp);
m_layout->addWidget(tmp->getUI()); m_layout->addWidget(tmp->getUI());
} }
// 如果是垂直布局,则添加 底部的弹簧
if (qobject_cast<QVBoxLayout * >(m_layout) != nullptr) {
QSpacerItem *verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
((QVBoxLayout*)m_layout)->addSpacerItem(verticalSpacer);
}
} }

Loading…
Cancel
Save