diff --git a/QtCheckHeaderView.cpp b/QtCheckHeaderView.cppindex 0b5e7e7..97f028c 100644--- a/QtCheckHeaderView.cpp+++ b/QtCheckHeaderView.cpp@@ -255,9 +255,7 @@ void QtCheckHeaderView::paintSection(QPainter* painter, const QRect& rect, int l // =============================================================== } else- { QHeaderView::paintSection(painter, rect, logicalIndex);- } } void QtCheckHeaderView::updateCheckbox(int logicalIndex)@@ -293,17 +291,11 @@ void QtCheckHeaderView::updateCheckbox(int logicalIndex) } } if (allunchecked)- { mCheckStates.insert(logicalIndex, Qt::Unchecked);- } else if (allchecked)- { mCheckStates.insert(logicalIndex, Qt::Checked);- } else- { mCheckStates.insert(logicalIndex, Qt::PartiallyChecked);- } } void QtCheckHeaderView::updateModel(int logicalIndex)@@ -311,16 +303,25 @@ void QtCheckHeaderView::updateModel(int logicalIndex) Qt::CheckState checked = mCheckStates.value(logicalIndex); if (orientation() == Qt::Horizontal)- { for (int i = 0; i < model()->rowCount(rootIndex()); ++i)- { model()->setData(model()->index(i, logicalIndex, rootIndex()), checked, Qt::CheckStateRole);- }- } else if (orientation() == Qt::Vertical)- {+ else if (orientation() == Qt::Vertical) for (int i = 0; i < model()->columnCount(rootIndex()); ++i)- { model()->setData(model()->index(logicalIndex, i, rootIndex()), checked, Qt::CheckStateRole);- }- }+}++QSize QtCheckHeaderView::sectionSizeFromContents(int logicalIndex) const+{+ QStyleOptionHeader opt;+ initStyleOption(&opt);+ QStyleOptionButton option;+ option.QStyleOption::operator =(opt);++ QRect cr = style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt);+ QSize res = QHeaderView::sectionSizeFromContents(logicalIndex);+ if (orientation() == Qt::Horizontal)+ res.setWidth(res.width() + cr.width());+ else+ res.setHeight(res.height() + cr.height());+ return res; }diff --git a/QtCheckHeaderView.h b/QtCheckHeaderView.hindex 5fdd148..3281b08 100644--- a/QtCheckHeaderView.h+++ b/QtCheckHeaderView.h@@ -45,6 +45,8 @@ class QtCheckHeaderView: public QHeaderView void mousePressEvent(QMouseEvent* event); void paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const; + QSize sectionSizeFromContents(int logicalIndex) const;+ QList<int> mCheckableIndexes; QMap<int, Qt::CheckState> mCheckStates; bool blockDataChanged;