You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

qvaluecombobox.cpp 757B

12345678910111213141516171819202122232425262728293031
  1. // Copyright (c) 2011-2016 The Starwels developers
  2. // Distributed under the MIT software license, see the accompanying
  3. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. #include "qvaluecombobox.h"
  5. QValueComboBox::QValueComboBox(QWidget *parent) :
  6. QComboBox(parent), role(Qt::UserRole)
  7. {
  8. connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(handleSelectionChanged(int)));
  9. }
  10. QVariant QValueComboBox::value() const
  11. {
  12. return itemData(currentIndex(), role);
  13. }
  14. void QValueComboBox::setValue(const QVariant &value)
  15. {
  16. setCurrentIndex(findData(value, role));
  17. }
  18. void QValueComboBox::setRole(int _role)
  19. {
  20. this->role = _role;
  21. }
  22. void QValueComboBox::handleSelectionChanged(int idx)
  23. {
  24. Q_EMIT valueChanged();
  25. }