#include "loqtreewidget.h" #include void LoQTreeWidget::addFd() { fdCheckAll = new QCheckBox(this); connect(fdCheckAll, &QCheckBox::stateChanged, this, [=](int state) { if(state==Qt::PartiallyChecked) return; int cnt = topLevelItemCount(); for(int rr=0; rrisHidden()) topLevelItem(rr)->setCheckState(1, (Qt::CheckState) state); emit selChanged(); }); auto cellClicked = [=](QTreeWidgetItem *item, int column) { if(column > 2) return; if(! fdCheckAll->isVisible()) return; auto state = item->checkState(1)==Qt::Checked ? Qt::Unchecked : Qt::Checked; item->setCheckState(1, state); int cnt = topLevelItemCount(); fdCheckAll->blockSignals(true); for(int rr=0; rrisHidden() && topLevelItem(rr)->checkState(1)!=state) { fdCheckAll->setCheckState(Qt::PartiallyChecked); goto end; } fdCheckAll->setCheckState(state); end:fdCheckAll->blockSignals(false); emit selChanged(); }; connect(this, &QTreeWidget::itemClicked, this, cellClicked); connect(this, &QTreeWidget::itemEntered, this, [=](QTreeWidgetItem *item, int column) { if(column > 2) return; if(! fdCheckAll->isVisible()) return; if((QGuiApplication::mouseButtons() & Qt::LeftButton) == 0) return; cellClicked(item, column); }); } void LoQTreeWidget::updateGeometries() { QTreeWidget::updateGeometries(); if(fdCheckAll==0) return; fdCheckAll->move(columnWidth(0)+headerItem()->data(1, MarginRole).toInt()+4, 2); }