68 lines
1.6 KiB
C++
68 lines
1.6 KiB
C++
#include "CheckHeadView.h"
|
|
#include <QPainter>
|
|
#include <QCheckBox>
|
|
//#include <QDebug>
|
|
CheckHeadView::CheckHeadView(QVector<int> 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()));
|
|
|
|
}
|
|
|
|
|
|
}
|
|
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() + rect.width() / 4);
|
|
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();
|
|
} |