void QSpreadsheetHeaderView::mousePressEvent ( QMouseEvent * event ) { QHeaderView::mousePressEvent(event); int logicalIndex = logicalIndexAt(event->pos()); if (buttonMenuRect(logicalIndex).contains(event->pos())) { QMenu menu(this); QAction *hideCol = menu.addAction("Hide column"); QAction *sortAZ = menu.addAction("Sort sheet A->Z"); QAction *sortZA = menu.addAction("Sort sheet Z->A"); // Disable hide column if only one column remains. Otherwise // the gui is no more available to show them back. hideCol->setEnabled(hiddenSectionCount() < count() - 1); QAction *res = menu.exec(mapToGlobal(event->pos())); if (res == hideCol) { hideSection(logicalIndex); updateSection(logicalIndex-1); } if (res == sortAZ) model()->sort(logicalIndex, Qt::AscendingOrder); if (res == sortZA) model()->sort(logicalIndex, Qt::DescendingOrder); } // Catch previous arrow mouse click. if (prevRect(logicalIndex).contains(event->pos())) { showSection(logicalIndex - 1); updateSection(logicalIndex - 2); } // Catch next arrow mouse click. if (nextRect(logicalIndex).contains(event->pos())) { showSection(logicalIndex + 1); updateSection(logicalIndex + 2); } }
int ViewHeader::visibleSectionCount() const { return count() - hiddenSectionCount(); }