This commit is contained in:
Jack Mahoney 2026-01-07 16:36:03 -08:00 committed by GitHub
commit d3827155b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 85 additions and 1 deletions

View File

@ -341,6 +341,7 @@
|<<tabs.position,tabs.position>>|Position of the tab bar.
|<<tabs.select_on_remove,tabs.select_on_remove>>|Which tab to select when the focused tab is removed.
|<<tabs.show,tabs.show>>|When to show the tab bar.
|<<tabs.show_on_close,tabs.show_on_close>>|Show the tab bar for a short duration when a tab is closed, if tabs.show is set to 'switching'.
|<<tabs.show_switching_delay,tabs.show_switching_delay>>|Duration (in milliseconds) to show the tab bar before hiding it when tabs.show is set to 'switching'.
|<<tabs.tabs_are_windows,tabs.tabs_are_windows>>|Open a new window for every tab.
|<<tabs.title.alignment,tabs.title.alignment>>|Alignment of the text inside of tabs.
@ -4523,6 +4524,14 @@ Valid values:
Default: +pass:[always]+
[[tabs.show_on_close]]
=== tabs.show_on_close
Show the tab bar for a short duration when a tab is closed, if tabs.show is set to 'switching'.
Type: <<types,Bool>>
Default: +pass:[false]+
[[tabs.show_switching_delay]]
=== tabs.show_switching_delay
Duration (in milliseconds) to show the tab bar before hiding it when tabs.show is set to 'switching'.

View File

@ -2360,6 +2360,13 @@ tabs.show_switching_delay:
desc: "Duration (in milliseconds) to show the tab bar before hiding it when
tabs.show is set to 'switching'."
tabs.show_on_close:
type: Bool
default: false
desc: >-
Show the tab bar for a short duration when a tab is closed, if
tabs.show is set to 'switching'.
tabs.tabs_are_windows:
default: false
type: Bool

View File

@ -407,6 +407,7 @@ class TabBar(QTabBar):
# Otherwise, we get "Cannot determine type of "drag_in_progress" in
# TabWidget._toggle_visibility below.
self.drag_in_progress: bool = False
self._closing: bool = False
stylesheet.set_register(self)
self.ensurePolished()
config.instance.changed.connect(self._on_config_changed)
@ -467,6 +468,8 @@ class TabBar(QTabBar):
def on_current_changed(self):
"""Show tab bar when current tab got changed."""
if self._closing:
return
self.maybe_hide() # for fullscreen tabs
if config.val.tabs.show == 'switching':
self.show()
@ -746,7 +749,16 @@ class TabBar(QTabBar):
def tabRemoved(self, idx):
"""Update visibility when a tab was removed."""
super().tabRemoved(idx)
self.maybe_hide()
self._closing = True
try:
if (config.val.tabs.show_on_close and
config.val.tabs.show == 'switching'):
self.show()
self._auto_hide_timer.start()
else:
self.maybe_hide()
finally:
self._closing = False
def wheelEvent(self, e):
"""Override wheelEvent to make the action configurable.

View File

@ -187,3 +187,59 @@ class TestTabWidget:
widget.addTab(fake_web_tab(), 'foobar')
tab_bar = widget.tabBar()
benchmark(functools.partial(tab_bar._tab_pinned, 0))
class TestTabBarShowOnClose:
@pytest.fixture
def widget(self, qtbot, monkeypatch, config_stub, fake_web_tab):
"""A tab widget with two tabs."""
w = tabwidget.TabWidget(0)
qtbot.add_widget(w)
monkeypatch.setattr(tabwidget.objects, 'backend',
usertypes.Backend.QtWebKit)
w.addTab(fake_web_tab(), 'tab1')
w.addTab(fake_web_tab(), 'tab2')
w.show()
return w
def test_show_on_close_true_and_switching(self, widget, config_stub, qtbot):
"""Test tabs.show_on_close=True and tabs.show='switching'."""
config_stub.val.tabs.show = 'switching'
config_stub.val.tabs.show_on_close = True
tab_bar = widget.tabBar()
qtbot.wait(1)
assert not tab_bar.isVisible()
widget.removeTab(0)
assert tab_bar.isVisible()
qtbot.wait(config_stub.val.tabs.show_switching_delay)
assert not tab_bar.isVisible()
def test_show_on_close_false(self, widget, config_stub, qtbot):
"""Test tabs.show_on_close=False."""
config_stub.val.tabs.show = 'switching'
config_stub.val.tabs.show_on_close = False
tab_bar = widget.tabBar()
qtbot.wait(1)
assert not tab_bar.isVisible()
widget.removeTab(0)
assert not tab_bar.isVisible()
@pytest.mark.parametrize('show_val,is_visible', [
('always', True),
('never', False),
])
def test_show_on_close_true_not_switching(self, widget, config_stub, qtbot,
show_val, is_visible):
"""Test tabs.show_on_close=True and tabs.show!='switching'."""
config_stub.val.tabs.show = show_val
config_stub.val.tabs.show_on_close = True
tab_bar = widget.tabBar()
qtbot.wait(1)
assert tab_bar.isVisible() is is_visible
widget.removeTab(0)
assert tab_bar.isVisible() is is_visible