Source code for labscript_utils.qtwidgets.fingertab
# Code by LegoStormtroopr
#
# License:
# This [trivial fingertab gist](https://gist.github.com/LegoStormtroopr/5075267) is released
# as Public Domain, but boy would it beswell if you could credit me, or tweet me
# [@LegoStormtoopr](http://www.twitter.com/legostormtroopr) to say thanks!
from qtutils.qt import QtCore, QtWidgets
[docs]
class FingerTabBarWidget(QtWidgets.QTabBar):
[docs]
def __init__(self, parent=None, *args, **kwargs):
self.tabSize = QtCore.QSize(kwargs.pop('width', 100), kwargs.pop('height', 25))
QtWidgets.QTabBar.__init__(self, parent, *args, **kwargs)
[docs]
def paintEvent(self, event):
painter = QtWidgets.QStylePainter(self)
option = QtWidgets.QStyleOptionTab()
for index in range(self.count()):
self.initStyleOption(option, index)
tabRect = self.tabRect(index)
tabRect.moveLeft(10)
painter.drawControl(QtWidgets.QStyle.ControlElement.CE_TabBarTabShape, option)
painter.drawText(tabRect, QtCore.Qt.AlignmentFlag.AlignVCenter |
QtCore.Qt.TextFlag.TextDontClip,
self.tabText(index))
painter.end()
# Shamelessly stolen from this thread:
# http://www.riverbankcomputing.com/pipermail/pyqt/2005-December/011724.html
[docs]
class FingerTabWidget(QtWidgets.QTabWidget):
"""A QTabWidget equivalent which uses our FingerTabBarWidget"""
[docs]
def __init__(self, parent, *args):
QtWidgets.QTabWidget.__init__(self, parent, *args)
self.setTabBar(FingerTabBarWidget(self))
#A simple test!
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
tabs = QtWidgets.QTabWidget()
tabs.setTabBar(FingerTabBarWidget(width=100,height=25))
digits = ['Thumb','Pointer','Rude','Ring','Pinky']
for i,d in enumerate(digits):
widget = QtWidgets.QLabel("Area #%s <br> %s Finger"% (i,d))
tabs.addTab(widget, d)
tabs.setTabPosition(QtWidgets.QTabWidget.TabPosition.East)
tabs.show()
sys.exit(app.exec_())