void DiagramViewWrapper::headerDataChanged(Qt::Orientation orientation, int first, int last) { if (orientation == Qt::Horizontal) { for (int section = first; section <= last; ++section) { QCheckBox* cbox = m_lstCb[section]; cbox->setText(model()->headerData(section, orientation).toString()); // color highlight QPalette p = cbox->palette(); QColor clrBkgd = qvariant_cast<QColor>(model()->headerData(section, Qt::Horizontal, Qt::DecorationRole)); p.setColor(cbox->backgroundRole(), clrBkgd); if (clrBkgd.lightnessF() < 0.5) { p.setColor(cbox->foregroundRole(), Qt::white); } cbox->setPalette(p); cbox->setAutoFillBackground(true); } } }