VCheckBox.cpp 1.9 KB

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