You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.2 KiB
C++
90 lines
2.2 KiB
C++
3 weeks ago
|
#include "CUIComboBox.h"
|
||
|
|
||
|
#include<CUIConfig.h>
|
||
|
#include<QHBoxLayout>
|
||
|
#include<CUI.h>
|
||
|
#include<QLabel>
|
||
|
#include<QDebug>
|
||
|
#include<QAbstractItemView>
|
||
|
|
||
|
/**
|
||
|
* @brief CUIComboBox::CUIComboBox 构造函数
|
||
|
* @param conf 配置信息
|
||
|
* @param parent
|
||
|
*/
|
||
|
CUIComboBox::CUIComboBox(CUIConfig* conf, QVector<CUI*> &subCUI, QWidget *parent) : QWidget(parent)
|
||
|
{
|
||
|
this->conf = conf;
|
||
|
iniUI(subCUI);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief CUIComboBox::getLabelWidth 获取combobox的label的最小宽度
|
||
|
* @return label的最小宽度
|
||
|
*/
|
||
|
qint32 CUIComboBox::getLabelWidth()
|
||
|
{
|
||
|
return label->minimumSizeHint().width();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief CUIComboBox::setLabelWidth 设置label的宽度
|
||
|
* @param width 宽度
|
||
|
*/
|
||
|
void CUIComboBox::setLabelWidth(qint32 width)
|
||
|
{
|
||
|
label->setMinimumWidth(width);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @brief CUIComboBox::iniUI 初始化widget,添加label和comboBox
|
||
|
*/
|
||
|
void CUIComboBox::iniUI(QVector<CUI*> &subCUI)
|
||
|
{
|
||
|
label = new QLabel(conf->property["name"]);
|
||
|
comboBox = new QComboBox;
|
||
|
layout = new QHBoxLayout;
|
||
|
this->setLayout(layout);
|
||
|
layout->addWidget(label);
|
||
|
layout->addWidget(comboBox);
|
||
|
|
||
|
// layout->setStretchFactor(label,1);
|
||
|
layout->setStretchFactor(comboBox,1);
|
||
|
// comboBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
|
||
|
// comboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||
|
// label->setMinimumWidth(114);
|
||
|
|
||
|
qDebug()<<label->minimumSizeHint()<<" combobox";
|
||
|
|
||
|
iniComoboBox();
|
||
|
connect(comboBox,QOverload<int>::of(&QComboBox::activated),[=](int idx){
|
||
|
qDebug()<<comboBox->itemData(idx);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief CUIComboBox::iniComoboBox 初始化ComboBox
|
||
|
*/
|
||
|
void CUIComboBox::iniComoboBox()
|
||
|
{
|
||
|
for(auto cui:conf->sub){
|
||
|
if(cui->property["type"] != "Item"){
|
||
|
qDebug()<<"wrong type!!!";
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
CUI* temp = new CUI(cui);
|
||
|
Items.push_back(temp);
|
||
|
|
||
|
if(temp->getProperty("data_type") == "int")
|
||
|
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());
|
||
|
else
|
||
|
comboBox->addItem(temp->getProperty("name"),temp->getProperty("data"));
|
||
|
|
||
|
}
|
||
|
}
|