void RDHeaderView::cacheSectionMinSizes() { m_sectionMinSizes.resize(count()); m_sectionMinSizesTotal = 0; for(int i = 0; i < m_sectionMinSizes.count(); i++) { int sz = 0; // see if we can fetch the column/row size hint from the item view QAbstractItemView *view = qobject_cast<QAbstractItemView *>(parent()); if(view) { if(orientation() == Qt::Horizontal) sz = view->sizeHintForColumn(i); else sz = view->sizeHintForRow(i); } // also include the size for the header as another minimum if(orientation() == Qt::Horizontal) sz = qMax(sz, sectionSizeFromContents(i).width()); else sz = qMax(sz, sectionSizeFromContents(i).height()); // finally respect the minimum section size specified sz = qMax(sz, minimumSectionSize()); // update the minimum size for this section and count the total which we'll need m_sectionMinSizes[i] = sz; m_sectionMinSizesTotal += m_sectionMinSizes[i]; } }
void CCustomHeaderView::onSectionResized(int section, int oldSize, int newSize) { int iPrevSectionSize(-1); QSize sEntrySize = sectionSizeFromContents(section); CCustomHeaderViewEntry * ptrPrevEntry; int iCount = m_ptrPriv->sectionsCount(); if (section < iCount) { //get resized section size CCustomHeaderViewEntry * ptrEntry = m_ptrPriv->m_vSectionsWidget[section]; if (orientation()==Qt::Horizontal) sEntrySize = QSize(newSize-ciEntrySeparator,m_ptrPriv->m_sectionSize.height()-ciEntrySeparator); else sEntrySize = QSize(m_ptrPriv->m_sectionSize.width()-ciEntrySeparator,newSize-ciEntrySeparator); ptrEntry->setFixedSize(sEntrySize); ptrPrevEntry = ptrEntry; //if (section==0) // iPrevSectionSize = sEntrySize.width(); } else return; //change position of all NEXT widgets for(int i = section+1;i<iCount;i++) { sEntrySize = ptrPrevEntry->minimumSize(); QPoint ptPos = ptrPrevEntry->pos(); if (iPrevSectionSize==-1) { if (orientation()==Qt::Horizontal) ptPos.rx()+=sEntrySize.width()+ciEntrySeparator; else ptPos.ry()+=sEntrySize.height()+ciEntrySeparator; } else { if (orientation()==Qt::Horizontal) ptPos.rx()+=iPrevSectionSize+ciEntrySeparator; else ptPos.ry()+=iPrevSectionSize+ciEntrySeparator; iPrevSectionSize=-1; } CCustomHeaderViewEntry * ptrEntry = m_ptrPriv->m_vSectionsWidget[i]; ptrEntry->move(ptPos); ptrPrevEntry = ptrEntry; } }