From 13ff604e5bd84fbfd63e666c6dacd149fd50d9a9 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 1 Jun 2018 16:40:36 +0200 Subject: Middle mouse button closes tab --- src/mainwindow/widgets/tabwidget.cpp | 14 ++++++++++++++ src/mainwindow/widgets/tabwidget.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/mainwindow/widgets/tabwidget.cpp b/src/mainwindow/widgets/tabwidget.cpp index 48a1cfb..2858fb0 100644 --- a/src/mainwindow/widgets/tabwidget.cpp +++ b/src/mainwindow/widgets/tabwidget.cpp @@ -123,3 +123,17 @@ void TabWidget::contextMenuEvent(QContextMenuEvent *event) tabContextMenu->exec(event->globalPos()); } + +void TabWidget::mousePressEvent(QMouseEvent *event) +{ + if(event->button() == Qt::MiddleButton) { + int index = tabBar()->tabAt(event->pos()); + if(index >= 0) { + deleteTab(index); + } + event->accept(); + return; + } + + QTabWidget::mousePressEvent(event); +} diff --git a/src/mainwindow/widgets/tabwidget.h b/src/mainwindow/widgets/tabwidget.h index 06fa79b..793e041 100644 --- a/src/mainwindow/widgets/tabwidget.h +++ b/src/mainwindow/widgets/tabwidget.h @@ -28,6 +28,7 @@ public slots: protected: void contextMenuEvent(QContextMenuEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; private: QMenu *tabContextMenu; -- cgit v1.2.1