Fix close-on-right-click for tabs.
This commit is contained in:
parent
e170193275
commit
86edda69c1
2
doc/BUGS
2
doc/BUGS
@ -20,8 +20,6 @@ Bugs
|
|||||||
|
|
||||||
- The concept of "default keybindings always get added" is confusing.
|
- The concept of "default keybindings always get added" is confusing.
|
||||||
|
|
||||||
- tabbar -> close-on-right-click is broken
|
|
||||||
|
|
||||||
- seir sometimes sees "-- COMMAND MODE --" even though that should never
|
- seir sometimes sees "-- COMMAND MODE --" even though that should never
|
||||||
happen.
|
happen.
|
||||||
|
|
||||||
|
@ -102,6 +102,7 @@ class TabbedBrowser(TabWidget):
|
|||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
self.tabBar().tab_rightclicked.connect(self.on_tab_close_requested)
|
||||||
self.tabCloseRequested.connect(self.on_tab_close_requested)
|
self.tabCloseRequested.connect(self.on_tab_close_requested)
|
||||||
self.currentChanged.connect(self.on_current_changed)
|
self.currentChanged.connect(self.on_current_changed)
|
||||||
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
"""The tab widget used for TabbedBrowser from browser.py."""
|
"""The tab widget used for TabbedBrowser from browser.py."""
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSlot, Qt, QSize
|
from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QSize
|
||||||
from PyQt5.QtWidgets import QTabWidget, QTabBar, QSizePolicy
|
from PyQt5.QtWidgets import QTabWidget, QTabBar, QSizePolicy
|
||||||
from PyQt5.QtGui import QIcon, QPixmap
|
from PyQt5.QtGui import QIcon, QPixmap
|
||||||
|
|
||||||
@ -121,7 +121,18 @@ class TabWidget(QTabWidget):
|
|||||||
|
|
||||||
class TabBar(QTabBar):
|
class TabBar(QTabBar):
|
||||||
|
|
||||||
"""Custom tabbar to close tabs on right click."""
|
"""Custom tabbar to close tabs on right click.
|
||||||
|
|
||||||
|
Signals:
|
||||||
|
tab_rightclicked: Emitted when a tab was right-clicked and should be
|
||||||
|
closed. We use this rather than tabCloseRequested
|
||||||
|
because tabCloseRequested is sometimes connected by
|
||||||
|
Qt to the tabwidget and sometimes not, depending on
|
||||||
|
if close buttons are enabled.
|
||||||
|
arg: The tab index to be closed.
|
||||||
|
"""
|
||||||
|
|
||||||
|
tab_rightclicked = pyqtSignal(int)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<{} with {} tabs>'.format(self.__class__.__name__,
|
return '<{} with {} tabs>'.format(self.__class__.__name__,
|
||||||
@ -129,8 +140,7 @@ class TabBar(QTabBar):
|
|||||||
|
|
||||||
def mousePressEvent(self, e):
|
def mousePressEvent(self, e):
|
||||||
"""Override mousePressEvent to emit tabCloseRequested on rightclick."""
|
"""Override mousePressEvent to emit tabCloseRequested on rightclick."""
|
||||||
if (e.button() != Qt.RightButton or
|
if e.button() != Qt.RightButton:
|
||||||
not config.get('tabbar', 'close-on-right-click')):
|
|
||||||
super().mousePressEvent(e)
|
super().mousePressEvent(e)
|
||||||
return
|
return
|
||||||
idx = self.tabAt(e.pos())
|
idx = self.tabAt(e.pos())
|
||||||
@ -138,7 +148,8 @@ class TabBar(QTabBar):
|
|||||||
super().mousePressEvent(e)
|
super().mousePressEvent(e)
|
||||||
return
|
return
|
||||||
e.accept()
|
e.accept()
|
||||||
self.tabCloseRequested.emit(idx)
|
if config.get('tabbar', 'close-on-right-click'):
|
||||||
|
self.tab_rightclicked.emit(idx)
|
||||||
|
|
||||||
def tabSizeHint(self, index):
|
def tabSizeHint(self, index):
|
||||||
"""Override tabSizeHint so all tabs are the same size.
|
"""Override tabSizeHint so all tabs are the same size.
|
||||||
|
Loading…
Reference in New Issue
Block a user