| 205 | } |
| 206 | |
| 207 | void CCheckBoxHeader::mousePressEvent(QMouseEvent *event) |
| 208 | { |
| 209 | int logical = logicalIndexAt(event->pos()); |
| 210 | if (logical >= 0 && isCheckable(logical)) { |
| 211 | // 使用 sectionViewportPosition + sectionSize 构造节矩形,避免兼容性问题 |
| 212 | int x = sectionViewportPosition(logical); |
| 213 | int w = sectionSize(logical); |
| 214 | QRect sectionRect; |
| 215 | sectionRect = QRect(x, 0, w, height()); |
| 216 | if (CheckboxRect(sectionRect).contains(event->pos())) { |
| 217 | Qt::CheckState state = GetCheckState(logical); |
| 218 | switch (state) { |
| 219 | case Qt::Unchecked: |
| 220 | state = Qt::PartiallyChecked; |
| 221 | break; |
| 222 | case Qt::PartiallyChecked: |
| 223 | state = Qt::Checked; |
| 224 | break; |
| 225 | case Qt::Checked: |
| 226 | state = Qt::Unchecked; |
| 227 | break; |
| 228 | } |
| 229 | SetCheckState(logical, state); |
| 230 | emit sigCheckStateChanged(logical, state); |
| 231 | // 结束事件以避免触发排序(如不需要可调整) |
| 232 | //event->accept(); |
| 233 | //return; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | QHeaderView::mousePressEvent(event); |
| 238 | } |