1、先写固定的label宽度;

feature/struct-menu-20241023
simonyan 2 weeks ago
parent 75fd950ebf
commit a8ea239566

@ -1,4 +1,4 @@
#include "CUIComboBox.h"
#include "CUIComboBox.h"
#include<CUIConfig.h>
#include<QHBoxLayout>
@ -12,9 +12,9 @@
* @param conf
* @param parent
*/
CUIComboBox::CUIComboBox(CUIConfig* conf, QVector<CUI*> &subCUI, QWidget *parent) : QWidget(parent)
CUIComboBox::CUIComboBox(CUIConfig* conf, QVector<CUI*> &subCUI, QWidget *parent) : CUIComponentBaseWidget(parent)
{
this->conf = conf;
this->m_conf = conf;
initUI(subCUI);
}
@ -24,7 +24,7 @@ CUIComboBox::CUIComboBox(CUIConfig* conf, QVector<CUI*> &subCUI, QWidget *parent
*/
qint32 CUIComboBox::getLabelWidth()
{
return label->minimumSizeHint().width();
return m_label->minimumSizeHint().width();
}
/**
@ -33,7 +33,7 @@ qint32 CUIComboBox::getLabelWidth()
*/
void CUIComboBox::setLabelWidth(qint32 width)
{
label->setMinimumWidth(width);
m_label->setMinimumWidth(width);
}
@ -43,18 +43,17 @@ void CUIComboBox::setLabelWidth(qint32 width)
*/
void CUIComboBox::initUI(QVector<CUI*> &subCUI)
{
label = new QLabel(conf->getPropertyValue("name"));
comboBox = new QComboBox;
layout = new QHBoxLayout;
this->setLayout(layout);
layout->addWidget(label);
layout->addWidget(comboBox);
layout->setStretchFactor(comboBox, 1);
m_label = new QLabel(m_conf->getPropertyValue("name"));
m_label->setFixedWidth(m_labelLength);
m_comboBox = new QComboBox;
m_layout = new QHBoxLayout;
this->setLayout(m_layout);
m_layout->addWidget(m_label);
m_layout->addWidget(m_comboBox);
((QHBoxLayout*)m_layout)->setStretchFactor(m_comboBox, 1);
iniComoboBox();
connect(comboBox, QOverload<int>::of(&QComboBox::activated), [ = ](int idx) {
this->conf->setValue(idx);
connect(m_comboBox, QOverload<int>::of(&QComboBox::activated), [ = ](int idx) {
this->m_conf->setValue(idx);
});
}
@ -63,26 +62,24 @@ void CUIComboBox::initUI(QVector<CUI*> &subCUI)
*/
void CUIComboBox::iniComoboBox()
{
for(auto cui : conf->getSub()) {
for(auto cui : m_conf->getSub()) {
QString type = cui->getPropertyValue("type");
if(type != "Item") {
return;
}
CUI* temp = new CUI(nullptr, cui);
Items.push_back(temp);
m_items.push_back(temp);
if(temp->getProperty("data_type") == "int") {
comboBox->addItem(temp->getProperty("name"), temp->getProperty("data").toInt());
m_comboBox->addItem(temp->getProperty("name"), temp->getProperty("data").toInt());
} else if(temp->getProperty("data_type") == "double") {
comboBox->addItem(temp->getProperty("name"), temp->getProperty("data").toDouble());
m_comboBox->addItem(temp->getProperty("name"), temp->getProperty("data").toDouble());
} else {
comboBox->addItem(temp->getProperty("name"), temp->getProperty("data"));
m_comboBox->addItem(temp->getProperty("name"), temp->getProperty("data"));
}
}
QVariant vOrigin = conf->getPropertyOriginValue("value_origin");
QVariant vOrigin = m_conf->getPropertyOriginValue("value_origin");
int *ptr = qvariant_cast<int *>(vOrigin);
if(ptr!=nullptr)
{
comboBox->setCurrentIndex(*ptr);
if(ptr != nullptr) {
m_comboBox->setCurrentIndex(*ptr);
}
}

@ -1,7 +1,9 @@
#ifndef CUICOMBOBOX_H
#ifndef CUICOMBOBOX_H
#define CUICOMBOBOX_H
#include <QWidget>
#include "CUIComponentBaseWidget.h"
#include "CUIComponentBase.h"
#include <QComboBox>
class CUIConfig;
@ -9,7 +11,7 @@ class CUI;
class QLabel;
class QHBoxLayout;
class CUIComboBox : public QWidget
class CUIComboBox : public CUIComponentBaseWidget, public CUIComponentBase
{
Q_OBJECT
public:
@ -17,13 +19,11 @@ public:
qint32 getLabelWidth();
void setLabelWidth(qint32 width);
private:
void initUI(QVector<CUI*> &subCUI);
virtual void initUI(QVector<CUI*> &subCUI);
void iniComoboBox();
QComboBox* comboBox;
QLabel* label;
CUIConfig* conf;
QVector<CUI*> Items;
QHBoxLayout* layout;
QComboBox* m_comboBox;
QLabel* m_label;
QVector<CUI*> m_items;
signals:
};

@ -1,4 +1,4 @@
#ifndef CUICOMPONENTBASEWIDGET_H
#ifndef CUICOMPONENTBASEWIDGET_H
#define CUICOMPONENTBASEWIDGET_H
#include <QWidget>
@ -14,6 +14,7 @@ protected:
virtual void initUI();
protected:
QLayout* m_layout = nullptr;
int m_labelLength = 100;
signals:
};

@ -1,4 +1,4 @@
#include "CUILineEdit.h"
#include "CUILineEdit.h"
#include <QHBoxLayout>
#include <CUIConfig.h>
@ -46,6 +46,7 @@ void CUILineEdit::initUI(QVector<CUI*> &subCUI)
{
m_layout = new QHBoxLayout();
m_label = new QLabel(m_conf->getPropertyValue("name"));
m_label->setFixedWidth(m_labelLength);
m_lineEdit = new QLineEdit(this->getValueString());
m_layout->addWidget(m_label);
m_layout->addWidget(m_lineEdit);
@ -82,7 +83,7 @@ void CUILineEdit::setInputTips()
msg += m_inclusiveMax ? "]" : ")";
}
if(m_required) {
msg += "\t(必填)";
msg += "\t" + tr("(required)");
}
m_lineEdit->setPlaceholderText(msg);
}

@ -1,4 +1,4 @@
#include "CUIMultiTableWidget.h"
#include "CUIMultiTableWidget.h"
#include <QTableWidget>
#include <QTableWidgetItem>
#include <QHeaderView>
@ -16,7 +16,7 @@ CUIMultiTableWidget::CUIMultiTableWidget(CUIConfig* conf, QVector<CUI*> &subCUI,
void CUIMultiTableWidget::initUI()
{
QStringList headers;
headers<<tr("index")<<tr("name")<<tr("view");
headers << tr("index") << tr("name") << tr("alias") << tr("view");
QList<QList<QString >> items;
QList<QString> item1 = {tr("quaility"), "quaility"};
QList<QString> item2 = {tr("x"), "x"};
@ -28,7 +28,7 @@ void CUIMultiTableWidget::initUI()
items.append(item4);
// 根据配置来初始化tableWidget
m_tableWidget = new QTableWidget(this);
m_tableWidget->setColumnCount(items.count() + 2);
m_tableWidget->setColumnCount(items[0].count() + 2);
m_tableWidget->setRowCount(items.count());
m_tableWidget->setHorizontalHeaderLabels(headers);
// 设置水平表头的背景颜色
@ -38,7 +38,6 @@ void CUIMultiTableWidget::initUI()
// 隐藏垂直表头
QHeaderView *verticalHeader = m_tableWidget->verticalHeader();
verticalHeader->setVisible(false);
for (int i = 0; i < items.count(); i++) {
QList<QString> item = items[i];
// 序号
@ -60,7 +59,6 @@ void CUIMultiTableWidget::initUI()
checkBox->setStyleSheet("margin-left:45%; margin-right:45%;");// 设置水平居中
m_tableWidget->setCellWidget(i, item.count() + 1, checkBox);
}
m_layout = new QVBoxLayout;
m_layout->addWidget(m_tableWidget);
this->setLayout(m_layout);

Loading…
Cancel
Save