-
-
Save davidruffner/f9bfc851be71cb9ace6c818390e2f7a2 to your computer and use it in GitHub Desktop.
'FingerTabs' - Horizontal Text, Horizontal Tabs in PyQt Forked from [LegoStormtroopr's gist](https://gist.github.com/LegoStormtroopr/5075267).
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, FingerTabBarWidget | |
import sys | |
app = QtGui.QApplication(sys.argv) | |
tabs = QtGui.QTabWidget() | |
tabBar = FingerTabBarWidget(width=100,height=25) | |
tabs.setTabBar(tabBar) | |
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.tabCloseRequested.connect(tabs.removeTab) | |
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) | |
self.setTabsClosable(True) | |
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 [gist](https://gist.github.com/davidruffner/f9bfc851be71cb9ace6c818390e2f7a2) is released as Public Domain. It is a minor edit from [LegoStormtroopr's gist](https://gist.github.com/LegoStormtroopr/5075267). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment