12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #include "ComboBoxWidget.h"
- #include "DebugUtil.h"
- const QString ComboBoxWidget::type = "ComboBox";
- ComboBoxWidget::ComboBoxWidget(QWidget *parent)
- :QComboBox(parent)
- {
- setStyleSheet("QComboBox QAbstractItemView {\
- color:#333333;\
- border: 1px solid #555555;\
- background-color: #ffffff;\
- border-radius:3px;\
- }");
- }
- QVariant ComboBoxWidget::getValue() const
- {
- return currentData();
- }
- void ComboBoxWidget::setValue(const QVariant &value)
- {
- setCurrentIndex(0);
- for (int index = 0; index < count(); ++index)
- {
- if (value == itemData(index))
- {
- setCurrentIndex(index);
- }
- }
- }
- bool ComboBoxWidget::isValueNull() const
- {
- if(currentIndex() == 0)
- return true;
- return false;
- }
- void ComboBoxWidget::clearInput()
- {
- setCurrentIndex(0);
- }
- void ComboBoxWidget::setOptions(const QVariantMap &options)
- {
- QComboBox::clear();
- addItem(QStringLiteral("请选择"), -1);
- for (auto iter = options.cbegin(); iter != options.cend(); ++iter)
- {
- // addItem(iter.key(), iter.value());
- addItem(iter.value().toString(), iter.key());
- }
- }
|