VComboBox.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include "VComboBox.h"
  2. VComboBox::VComboBox(
  3. QWidget* parent,
  4. const QPoint& pos,
  5. const QSize& size,
  6. CONTROL_PROPERTY* pProperty
  7. )
  8. : QComboBox(parent)
  9. , VControlObject(pProperty)
  10. {
  11. // 设置默认属性(初始化值或者外部传入值)
  12. // QComboBox::setText(m_Property.m_strText);
  13. QComboBox::setToolTip(m_Property.m_strTip);
  14. this->setTextColor(m_Property.m_clrText);
  15. this->setBgColor(m_Property.m_clrBg);
  16. QComboBox::setFont(m_Property.m_Font);
  17. QComboBox::setEnabled(m_Property.m_bEnable);
  18. // 设置尺寸
  19. if (size == DEFAULT_CONTROL_SIZE)
  20. {
  21. this->resize(DEFAULT_COMBO_SIZE);
  22. }
  23. else
  24. {
  25. this->resize(size);
  26. }
  27. // 设置中心点坐标
  28. QPoint tempPos;
  29. tempPos.setX(pos.x() - width() / 2);
  30. tempPos.setY(pos.y() - height() / 2);
  31. // 设置位置
  32. this->move(tempPos);
  33. m_pWidget = this;
  34. m_Type = VALUE_TYPE::Control_ComboBox;
  35. }
  36. VComboBox::~VComboBox()
  37. {
  38. }
  39. // 属性的实现函数
  40. //// 暂未实现
  41. //void VComboBox::setText(const QString& title)
  42. //{
  43. // //if (this->m_strText != title)
  44. // //{
  45. // // this->m_strText = title;
  46. // // // QComboBox::setText(title);
  47. // //}
  48. //
  49. // //qDebug() << m_strText;
  50. //
  51. // Q_UNUSED(title);
  52. //}
  53. void VComboBox::setTip(const QString& tip)
  54. {
  55. if (this->m_Property.m_strTip != tip)
  56. {
  57. this->m_Property.m_strTip = tip;
  58. QComboBox::setToolTip(tip);
  59. }
  60. }
  61. void VComboBox::setTextColor(const QColor& color)
  62. {
  63. QString qss = VControlObject::textColorQss(color);
  64. this->setStyleSheet(qss);
  65. }
  66. void VComboBox::setBgColor(const QColor& color)
  67. {
  68. QString qss = VControlObject::bgColorQss(color);
  69. this->setStyleSheet(qss);
  70. }
  71. void VComboBox::setFont(const QFont& font)
  72. {
  73. if (this->m_Property.m_Font != font)
  74. {
  75. this->m_Property.m_Font = font;
  76. QComboBox::setFont(font);
  77. }
  78. }
  79. void VComboBox::setEnable(const bool enable)
  80. {
  81. if (this->m_Property.m_bEnable != enable)
  82. {
  83. this->m_Property.m_bEnable = enable;
  84. QComboBox::setEnabled(enable);
  85. }
  86. }