1
0
Fork 0
mirror of synced 2024-06-02 02:34:40 +12:00
Rare/rare/components/tabs/tab_widgets.py

31 lines
1 KiB
Python
Raw Normal View History

from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QTabBar, QSizePolicy, QPushButton
2021-03-25 05:01:12 +13:00
class MainTabBar(QTabBar):
def __init__(self, parent=None):
super(MainTabBar, self).__init__(parent=parent)
self.setObjectName(type(self).__name__)
font = self.font()
font.setPointSize(font.pointSize() + 1)
font.setBold(True)
self.setFont(font)
self.expanded = -1
2021-03-25 05:01:12 +13:00
def tabSizeHint(self, index):
size = super(MainTabBar, self).tabSizeHint(index)
if index == self.expanded:
2021-03-25 05:01:12 +13:00
offset = self.width()
for index in range(self.count()):
offset -= super(MainTabBar, self).tabSizeHint(index).width()
2021-03-25 05:01:12 +13:00
size.setWidth(max(size.width(), size.width() + offset))
return size
class TabButtonWidget(QPushButton):
def __init__(self, icon: QIcon, tooltip: str = "", parent=None):
super(TabButtonWidget, self).__init__(parent=parent)
self.setObjectName(type(self).__name__)
self.setIcon(icon)
self.setToolTip(tooltip)