CheckHeaderView.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "CheckHeaderView.h"
  2. #include "CAppInfo.h"
  3. CheckHeaderView::CheckHeaderView(int checkColumnIndex,
  4. Qt::Orientation orientation,
  5. QWidget * parent ) :
  6. QHeaderView(orientation, parent)
  7. {
  8. // 创建checkbox;
  9. QString sCheckStyle = QString(R"(QCheckBox
  10. {
  11. outline: none;
  12. height:%1px;
  13. font-size:%2px;
  14. font-family:"Microsoft YaHei";
  15. font-weight:400;
  16. color:rgba(102,102,102,1);
  17. }
  18. QCheckBox::indicator
  19. {
  20. width:%3px;
  21. height:%4px;
  22. }
  23. QCheckBox::indicator:unchecked
  24. {
  25. border: %5px solid rgba(228,229,235,1);
  26. border-radius:%6px;
  27. background:rgba(239,240,245,1);
  28. }
  29. QCheckBox::indicator:checked
  30. {
  31. border-image: url(:/images/icon-checkbox-checked.png);
  32. })").arg((int)(g_appInfoPtr->m_fRate * 26))
  33. .arg((int)(g_appInfoPtr->m_fRate * 14))
  34. .arg((int)(g_appInfoPtr->m_fRate * 14))
  35. .arg((int)(g_appInfoPtr->m_fRate * 14))
  36. .arg((int)(g_appInfoPtr->m_fRate * 1))
  37. .arg((int)(g_appInfoPtr->m_fRate * 3));
  38. m_CheckIdex = checkColumnIndex;
  39. m_checkBox = new QCheckBox(this);
  40. m_checkBox->setStyleSheet(sCheckStyle);
  41. QObject::connect(m_checkBox, SIGNAL(stateChanged(int)), this, SLOT(stateChanged(int)));
  42. }
  43. void CheckHeaderView::stateChanged(int state)
  44. {
  45. emit checkboxStateChanged(state);
  46. }
  47. void CheckHeaderView::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
  48. {
  49. painter->save();
  50. QHeaderView::paintSection(painter, rect, logicalIndex);
  51. painter->restore();
  52. if (logicalIndex == m_CheckIdex)
  53. {
  54. m_checkBox->setGeometry(rect);
  55. }
  56. }