VListBox.cpp 1.7 KB

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