#include "CUIComboBox.h" #include #include #include #include #include #include /** * @brief CUIComboBox::CUIComboBox 构造函数 * @param conf 配置信息 * @param parent */ CUIComboBox::CUIComboBox(CUIConfig* conf, QVector &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 &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()<minimumSizeHint()<<" combobox"; iniComoboBox(); connect(comboBox,QOverload::of(&QComboBox::activated),[=](int idx){ qDebug()<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")); } }