VGroupBox.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include "VGroupBox.h"
  2. VGroupBox::VGroupBox(
  3. QWidget* parent,
  4. const QPoint& pos,
  5. const QSize& size,
  6. CONTROL_PROPERTY* pProperty
  7. )
  8. : QGroupBox(parent)
  9. , VControlObject(pProperty)
  10. {
  11. // 设置默认属性(初始化值或者外部传入值)
  12. if (m_Property.m_strText.isEmpty())
  13. {
  14. m_Property.m_strText = "Text";
  15. }
  16. QGroupBox::setTitle(m_Property.m_strText);
  17. QGroupBox::setToolTip(m_Property.m_strTip);
  18. this->setTextColor(m_Property.m_clrText);
  19. this->setBgColor(m_Property.m_clrBg);
  20. QGroupBox::setFont(m_Property.m_Font);
  21. QGroupBox::setEnabled(m_Property.m_bEnable);
  22. // 设置尺寸
  23. if (size == DEFAULT_CONTROL_SIZE)
  24. {
  25. this->resize(DEFAULT_GROUP_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_Groupbox;
  39. }
  40. VGroupBox::~VGroupBox()
  41. {
  42. }
  43. // 属性的实现函数
  44. void VGroupBox::setText(const QString& title)
  45. {
  46. if (this->m_Property.m_strText != title)
  47. {
  48. this->m_Property.m_strText = title;
  49. QGroupBox::setTitle(title);
  50. }
  51. }
  52. void VGroupBox::setTip(const QString& tip)
  53. {
  54. if (this->m_Property.m_strTip != tip)
  55. {
  56. this->m_Property.m_strTip = tip;
  57. QGroupBox::setToolTip(tip);
  58. }
  59. }
  60. void VGroupBox::setTextColor(const QColor& color)
  61. {
  62. QString qss = VControlObject::textColorQss(color);
  63. this->setStyleSheet(qss);
  64. }
  65. void VGroupBox::setBgColor(const QColor& color)
  66. {
  67. QString qss = VControlObject::bgColorQss(color);
  68. this->setStyleSheet(qss);
  69. }
  70. void VGroupBox::setFont(const QFont& font)
  71. {
  72. if (this->m_Property.m_Font != font)
  73. {
  74. this->m_Property.m_Font = font;
  75. QGroupBox::setFont(font);
  76. }
  77. }
  78. void VGroupBox::setEnable(const bool enable)
  79. {
  80. if (this->m_Property.m_bEnable != enable)
  81. {
  82. this->m_Property.m_bEnable = enable;
  83. QGroupBox::setEnabled(enable);
  84. }
  85. }