tabwidget: Clean up and fix minimumTabSizeHint.

See #283.

The width now accounts for the indicator, and the wrong docstring has been
removed.
This commit is contained in:
Florian Bruhin 2014-12-10 14:29:14 +01:00
parent bac30b9192
commit 92b9dc08f4

View File

@ -158,14 +158,7 @@ class TabBar(QTabBar):
super().mousePressEvent(e) super().mousePressEvent(e)
def minimumTabSizeHint(self, index): def minimumTabSizeHint(self, index):
"""Override minimumTabSizeHint because we want no hard minimum. """Set the minimum tab size to indicator/icon/... text.
There are two problems with having a hard minimum tab size:
- When expanding is True, the window will expand without stopping
on some window managers.
- We don't want the main window to get bigger with many tabs. If
nothing else helps, we *do* want the tabs to get smaller instead
of enforcing a minimum window size.
Args: Args:
index: The index of the tab to get a sizehint for. index: The index of the tab to get a sizehint for.
@ -175,17 +168,21 @@ class TabBar(QTabBar):
""" """
icon = self.tabIcon(index) icon = self.tabIcon(index)
padding_count = 0 padding_count = 0
if not icon.isNull(): if icon.isNull():
icon_size = QSize(0, 0)
else:
extent = self.style().pixelMetric(QStyle.PM_TabBarIconSize, None, extent = self.style().pixelMetric(QStyle.PM_TabBarIconSize, None,
self) self)
icon_size = icon.actualSize(QSize(extent, extent)) icon_size = icon.actualSize(QSize(extent, extent))
padding_count += 1 padding_count += 1
else: indicator_width = config.get('tabs', 'indicator-width')
icon_size = QSize(0, 0) if indicator_width != 0:
indicator_width += config.get('tabs', 'indicator-space')
padding_width = self.style().pixelMetric(PM_TabBarPadding, None, self) padding_width = self.style().pixelMetric(PM_TabBarPadding, None, self)
height = self.fontMetrics().height() height = self.fontMetrics().height()
width = (self.fontMetrics().size(0, '\u2026').width() + width = (self.fontMetrics().size(0, '\u2026').width() +
icon_size.width() + padding_count * padding_width) icon_size.width() + padding_count * padding_width +
indicator_width)
return QSize(width, height) return QSize(width, height)
def tabSizeHint(self, index): def tabSizeHint(self, index):