-
-
Save benjaminirving/eb47caa4f67359cb985a to your computer and use it in GitHub Desktop.
'FingerTabs' - Horizontal Text, Horizontal Tabs in PyQt 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!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyQt4 import QtGui, QtCore | |
from FingerTabs import FingerTabWidget | |
import sys | |
app = QtGui.QApplication(sys.argv) | |
tabs = QtGui.QTabWidget() | |
tabs.setTabBar(FingerTabBarWidget(width=100,height=25)) | |
digits = ['Thumb','Pointer','Rude','Ring','Pinky'] | |
for i,d in enumerate(digits): | |
widget = QtGui.QLabel("Area #%s <br> %s Finger"% (i,d)) | |
tabs.addTab(widget, d) | |
tabs.setTabPosition(QtGui.QTabWidget.West) | |
tabs.show() | |
sys.exit(app.exec_()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Updated so a PyQT4 Designer TabWidget can be promoted to a FingerTabWidget | |
from PyQt4 import QtGui, QtCore | |
class FingerTabBarWidget(QtGui.QTabBar): | |
def __init__(self, parent=None, *args, **kwargs): | |
self.tabSize = QtCore.QSize(kwargs.pop('width',100), kwargs.pop('height',25)) | |
QtGui.QTabBar.__init__(self, parent, *args, **kwargs) | |
def paintEvent(self, event): | |
painter = QtGui.QStylePainter(self) | |
option = QtGui.QStyleOptionTab() | |
for index in range(self.count()): | |
self.initStyleOption(option, index) | |
tabRect = self.tabRect(index) | |
tabRect.moveLeft(10) | |
painter.drawControl(QtGui.QStyle.CE_TabBarTabShape, option) | |
painter.drawText(tabRect, QtCore.Qt.AlignVCenter |\ | |
QtCore.Qt.TextDontClip, \ | |
self.tabText(index)); | |
painter.end() | |
def tabSizeHint(self,index): | |
return self.tabSize | |
# Shamelessly stolen from this thread: | |
# http://www.riverbankcomputing.com/pipermail/pyqt/2005-December/011724.html | |
class FingerTabWidget(QtGui.QTabWidget): | |
"""A QTabWidget equivalent which uses our FingerTabBarWidget""" | |
def __init__(self, parent, *args): | |
QtGui.QTabWidget.__init__(self, parent, *args) | |
self.setTabBar(FingerTabBarWidget(self)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment