#include "CheckHeadView.h" #include #include //#include CheckHeadView::CheckHeadView(QVector rCheckID,Qt::Orientation orientation, QWidget* parent) : QHeaderView(orientation, parent) , m_rCheckIDs(rCheckID) //, m_pCheckBox(new QCheckBox(this)) { setHighlightSections(false); setMouseTracking(true); // ÏìÓ¦Êó±ê // setSectionsClickable(true); for (int nIndex = 0; nIndex < m_rCheckIDs.size(); ++nIndex) { auto pCheck = new QCheckBox(this); m_rCheckBoxMap.insert(m_rCheckIDs[nIndex], pCheck); pCheck->setVisible(false); connect(pCheck, SIGNAL(clicked()), this, SLOT(OnChecked())); pCheck->setFixedSize(QSize(25,25)); } } CheckHeadView::~CheckHeadView() { } void CheckHeadView::OnChecked() { QCheckBox* pCheck = (QCheckBox*)sender(); for (auto rIter = m_rCheckBoxMap.begin(); rIter != m_rCheckBoxMap.end(); ++rIter) { if (rIter.value() == pCheck) { bool bStatus = pCheck->isChecked(); int nCol = rIter.key(); SignalStatus(nCol, bStatus); return; } } } void CheckHeadView::paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const { QHeaderView::paintSection(painter, rect, logicalIndex); //int nIndex = m_rCheckIDs.indexOf(logicalIndex); for (auto rIter = m_rCheckBoxMap.begin(); rIter != m_rCheckBoxMap.end(); ++rIter) { if (rIter.key() == logicalIndex) { QRect centerRect = rect; centerRect.setX(rect.x()); rIter.value()->setGeometry(centerRect); rIter.value()->setVisible(true); } } } QCheckBox* CheckHeadView::GetCheckBox(int nCol) { auto rFind= m_rCheckBoxMap.find(nCol); if(rFind == m_rCheckBoxMap.end()) return NULL; return rFind.value(); }