-
-
Save LegoStormtroopr/5075267 to your computer and use it in GitHub Desktop.
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_()) |
# 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 [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! |
@philipstarkey I've updated the gist to include a public domain licence.
@LegoStormtroopr Thanks! I will of course credit you :) (FYI, I expect to use it as part of a future release of an open source project: http://www.labscriptsuite.org )
Very nice work!
I turned on the 'tabsClosable' attribute and the X button is drawed in the center of tab's title. Any idea of how to fix this?
tabs.setTabsClosable(True)
Haha, fancy seeing you here @philipstarkey :p. Thanks for investigating the licensing, I'm using this in the Qt port of runviewer right now...
Thanks for the code @LegoStormTrooper!
Fantasy!!
Very handy. Thanks.
I think
from FingerTabs import FingerTabWidget
needs to be changed to
from FingerTabs import FingerTabWidget, FingerTabBarWidget
Hi!
Thank you for awesome piece of code!
One additional concern. This code does not run properly if you include icons in your tabs. The icons are not displayed... just text. Do you know how to implement this as well?
Thanks!
Really nice example!
I also am running into the issue that @jrvidotti raised: when making the tabs closeable the X button shows up in the center of the tab. I went ahead a posted a question to stack overflow about how to position the X button. Thanks again for creating this example!
@LegoStormtroopr I'd love to use FingerTabs in my own code. What license is your code released under? Would you consider licensing it under the 2-clause BSD license?
Cheers,