void showColumnsContextMenu(const QPoint& p, QTreeWidget& tree) { QMenu headerMenu(xi18nc("@title:menu", "Columns")); QHeaderView* header = tree.header(); for (qint32 i = 0; i < tree.model()->columnCount(); i++) { const int idx = header->logicalIndex(i); const QString text = tree.model()->headerData(idx, Qt::Horizontal).toString(); QAction* action = headerMenu.addAction(text); action->setCheckable(true); action->setChecked(!header->isSectionHidden(idx)); action->setData(idx); action->setEnabled(idx > 0); } QAction* action = headerMenu.exec(tree.header()->mapToGlobal(p)); if (action != nullptr) { const bool hidden = !action->isChecked(); tree.setColumnHidden(action->data().toInt(), hidden); if (!hidden) tree.resizeColumnToContents(action->data().toInt()); } }
//------------------------------------------------------------------------------------------------- void BachFolderBrowserTreeView::saveColumns( IniConfig & ini, const BachFolderBrowserTreeView::ColumnStructEx columns [] ) { QHeaderView * hdr = header(); for( int i=0; columns[i].name; i++ ) ini.writeInt( columns[i].iniName + QString("Size"), hdr->sectionSize( i ) ); for( int i=0; columns[i].name; i++ ) ini.writeInt( columns[i].iniName + QString("Index"), hdr->visualIndex( i ) ); for( int i=0; columns[i].name; i++ ) ini.writeBool( columns[i].iniName + QString("Hidden"), hdr->isSectionHidden( i ) ); }
QList<int> PlaylistView::GetEditableColumns() { QList<int> columns; QHeaderView* h = header(); for (int col = 0; col < h->count(); col++) { if (h->isSectionHidden(col)) continue; QModelIndex index = model()->index(0, col); if (index.flags() & Qt::ItemIsEditable) columns << h->visualIndex(col); } qSort(columns); return columns; }
void FilmsViewList::ShowHeaderContextMenu( const QPoint& pos ) { // Setup QHeaderView* header = horizontalHeader(); QMenu menu( tr("Columns") ); // "Title" always enabled // "Filename" and "Poster" always disabled for( int column = 1; column < model()->columnCount() - 2; ++column ) { QAction* action = menu.addAction( model()->headerData( column, Qt::Horizontal ).toString() ); action->setCheckable( true ); action->setChecked( !header->isSectionHidden( column ) ); action->setData( column ); } menu.addSeparator(); QAction* resetAction = menu.addAction( tr("Reset to defaults") ); resetAction->setData( model()->columnCount() ); // Show QAction* triggered = menu.exec( header->viewport()->mapToGlobal(pos) ); // Processing if( triggered != nullptr ) { int i = triggered->data().toInt(); if( i < model()->columnCount() ) { header->setSectionHidden( i, !header->isSectionHidden( i ) ); } else // "Reset to defaults" item { RestoreColumnsOrder(); SetDefaultColumnsView(); } SaveSettings(); } }
void ListingTable::buildHeaderSectionMenu(QMenu* menu) { QHeaderView* header = horizontalHeader(); QAction* scaleToFitAction = new QAction(tr("Scale To Fit Viewport"), menu); connect(scaleToFitAction, SIGNAL(triggered()), this, SLOT(scaleSectionsToFit())); menu->addAction(scaleToFitAction); menu->addSeparator(); int nc = model->columnCount(); for (int i = 0 ; i < nc ; i++) { QString headerStr = model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString(); QAction* action = new QAction(headerStr, menu); connect(action, SIGNAL(triggered()), this, SLOT(headerSectionVisibilityActionTriggered())); action->setData(i); action->setCheckable(true); action->setChecked(!header->isSectionHidden(i)); menu->addAction(action); } }
SimpleQTableViewWidthInterface::SimpleQTableViewWidthInterface(QTableView& tbl) : TableWidthInterface(tbl.model()->columnCount()), m_tbl(tbl), m_pModel(tbl.model()) { int nCols (m_pModel->columnCount()); m_vbBold.resize(nCols); QFont font (m_tbl.font()); font.setBold(true); QFontMetrics fontMetrics (font); QHeaderView* pHdr (tbl.horizontalHeader()); for (int j = 0; j < nCols; ++j) { if (pHdr->isSectionHidden(j)) { setFixedWidth(j, 0); } else { m_vnHdrWidth[j] = fontMetrics.width(m_pModel->headerData(j, Qt::Horizontal).toString()) + 8/*2*QApplication::style()->pixelMetric(QStyle::PM_DefaultFrameWidth)*/; // PM_DefaultFrameWidth is not THE thing to use, but it's one way to get some spacing for the header; (well it turned up to be too small, so it got replaced by 8; probably look at the source to see what should be used) } } }
void TreeWidget::paintEvent(QPaintEvent* event) { QTreeWidget::paintEvent(event); if(isVerticalGridLineShown && topLevelItemCount()){ QHeaderView* hv = header(); QPainter painter(viewport()); QPen oldPen = painter.pen(); painter.setPen(QPen(QColor::fromRgb(gridColorRGB))); for(int i = 0; i < hv->count(); ++i){ // draw only visible sections starting from second column if(hv->isSectionHidden(i) || hv->visualIndex(i) <= 0){ continue; } // position mapped to viewport int pos = hv->sectionViewportPosition(i) - 1; if(pos > 0){ painter.drawLine(QPoint(pos, 0), QPoint(pos, height())); } } painter.setPen(oldPen); } }
int HeaderView::isSectionHidden(lua_State * L) // ( int logicalIndex ) const : bool { QHeaderView* obj = QtObject<QHeaderView>::check( L, 1); Util::push( L, obj->isSectionHidden( Util::toInt( L, 2) ) ); return 1; }