From 99bd53de8927fd84b69d261595941fe8cb1ca9a7 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 23 May 2014 04:12:18 +0200 Subject: [PATCH] Close tabs on right click --- TODO | 1 - qutebrowser/widgets/_tabwidget.py | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 43142bccb..72be6f4b5 100644 --- a/TODO +++ b/TODO @@ -56,7 +56,6 @@ Improvements / minor features - Second column (flag): TRUE if domain starts with ., else FALSE - if a cookie is a http-only cookie domain is prepended with a #HttpOnly_ - Zoom with ctrl + mousewheel -- Close tabs on right click - search highlighting - max height for completion (be smaller if possible) - tab should directly insert word and space if there's only one option diff --git a/qutebrowser/widgets/_tabwidget.py b/qutebrowser/widgets/_tabwidget.py index 5c403e5b6..8f4734cf7 100644 --- a/qutebrowser/widgets/_tabwidget.py +++ b/qutebrowser/widgets/_tabwidget.py @@ -18,7 +18,7 @@ """The tab widget used for TabbedBrowser from browser.py.""" from PyQt5.QtCore import pyqtSlot, Qt -from PyQt5.QtWidgets import QTabWidget, QTabBar, QSizePolicy +from PyQt5.QtWidgets import QTabWidget, QTabBar, QSizePolicy, QTabBar from PyQt5.QtGui import QIcon, QPixmap import qutebrowser.config.config as config @@ -78,12 +78,14 @@ class TabWidget(QTabWidget): def __init__(self, parent): super().__init__(parent) + self.setTabBar(TabBar()) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.setStyle(Style(self.style())) set_register_stylesheet(self) self.setDocumentMode(True) self.setElideMode(Qt.ElideRight) self.tabBar().setDrawBase(False) + self.tabBar().tabCloseRequested.connect(self.tabCloseRequested) self._init_config() def _init_config(self): @@ -115,3 +117,17 @@ class TabWidget(QTabWidget): """Update attributes when config changed.""" if section == 'tabbar': self._init_config() + + +class TabBar(QTabBar): + + """Custom tabbar to close tabs on right click.""" + + def mousePressEvent(self, e): + """Override mousePressEvent to emit tabCloseRequested on rightclick.""" + if e.button() != Qt.RightButton: + return super().mousePressEvent(e) + idx = self.tabAt(e.pos()) + if idx == -1: + return super().mousePressEvent(e) + self.tabCloseRequested.emit(idx)