void MainTab::mousePressEvent(QMouseEvent* event) { if(event->buttons() == Qt::MidButton) { QTabBar* bar = tabBar(); m_index = bar->tabAt(bar->mapFrom(this, event->pos())); closeTab(); } QTabWidget::mousePressEvent(event); }
void MainTab::contextMenuEvent(QContextMenuEvent* event) { QTabBar* bar = tabBar(); m_index = bar->tabAt(bar->mapFrom(this, event->pos())); if(m_index < 0) return; QAction* action; QMenu menu(this); if(m_index > 3) { action = menu.addAction(tr("Close tab")); connect(action, SIGNAL(triggered()), this, SLOT(closeTab())); } action = menu.addAction(tr("Close all tabs")); connect(action, SIGNAL(triggered()), this, SLOT(closeAllTabs())); menu.exec(mapToGlobal(event->pos())); }