VLineEdit.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #include "VLineEdit.h"
  2. VLineEdit::VLineEdit(
  3. QWidget* parent,
  4. const QPoint& pos,
  5. const QSize& size,
  6. CONTROL_PROPERTY* pProperty
  7. )
  8. : QLineEdit(parent)
  9. , VControlObject(pProperty)
  10. {
  11. // 设置默认属性(初始化值或者外部传入值)
  12. if (m_Property.m_strText.isEmpty())
  13. {
  14. m_Property.m_strText = "LineEdit";
  15. }
  16. QLineEdit::setText(m_Property.m_strText);
  17. QLineEdit::setToolTip(m_Property.m_strTip);
  18. this->setTextColor(m_Property.m_clrText);
  19. this->setBgColor(m_Property.m_clrBg);
  20. QLineEdit::setFont(m_Property.m_Font);
  21. QLineEdit::setEnabled(m_Property.m_bEnable);
  22. // 设置尺寸
  23. if (size == DEFAULT_CONTROL_SIZE)
  24. {
  25. this->resize(DEFAULT_EDIT_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_LineEdit;
  39. }
  40. VLineEdit::~VLineEdit()
  41. {
  42. }
  43. // 属性的实现函数
  44. void VLineEdit::setText(const QString& title/*, bool bForce*/)
  45. {
  46. if (this->m_Property.m_strText != title)
  47. {
  48. this->m_Property.m_strText = title;
  49. QLineEdit::setText(title);
  50. }
  51. //if (bForce)
  52. //{
  53. // QLineEdit::setText(title);
  54. //}
  55. }
  56. void VLineEdit::setTip(const QString& tip)
  57. {
  58. if (this->m_Property.m_strTip != tip)
  59. {
  60. this->m_Property.m_strTip = tip;
  61. QLineEdit::setToolTip(tip);
  62. }
  63. }
  64. void VLineEdit::setTextColor(const QColor& color)
  65. {
  66. QString qss = VControlObject::textColorQss(color);
  67. this->setStyleSheet(qss);
  68. }
  69. void VLineEdit::setBgColor(const QColor& color)
  70. {
  71. QString qss = VControlObject::bgColorQss(color);
  72. this->setStyleSheet(qss);
  73. }
  74. void VLineEdit::setFont(const QFont& font)
  75. {
  76. if (this->m_Property.m_Font != font)
  77. {
  78. this->m_Property.m_Font = font;
  79. QLineEdit::setFont(font);
  80. }
  81. }
  82. void VLineEdit::setEnable(const bool enable)
  83. {
  84. if (this->m_Property.m_bEnable != enable)
  85. {
  86. this->m_Property.m_bEnable = enable;
  87. QLineEdit::setEnabled(enable);
  88. }
  89. }
  90. ///// <summary>
  91. ///// 控件文字变更时,需要与Runtime与Dll三方同步
  92. ///// </summary>
  93. ///// <param name="strText"></param>
  94. //void VLineEdit::onTextChanged(const QString& strText)
  95. //{
  96. // // qDebug() << "VLineEdit::onTextChanged";
  97. //
  98. // Q_UNUSED(strText);
  99. //
  100. // g_pUiManager->syncToDll(this, UI_SYNC_MSG::EDIT_TEXT_CHANGED);
  101. //}