Hello,

apparently the source text was a bit mangled on the way through the
mailing list,
so I re-send it as an attachment "hltabwidget.py".

The monkey-patching can also be done by simply importing this module before
any QTabWidget's  are instantiated.

Best regards,


Thilo Ernst, Fraunhofer FIRST


Thilo Ernst wrote:

Hello,


in our own simulation-related PyQt app as well as in eric3 we found that
[...]

import qt

class HighlightedTabBar(qt.QTabBar):
    """a tab bar where the label of the selected tab is painted underlined"""
    def paintLabel(self, painter, rect, tab, has_focus):
        # don't use QTabBar.currentTab() - here be dragons
        selected= (self.tabAt(self.indexOf(self.currentTab()))==tab)
        if selected: 
              painter.save()
              # options for style emphasis: foreground/background colors don't work.
              # Bold works but disturbs the font metrics. Underline Just Works.
              painter.font().setUnderline(True)         
        qt.QTabBar.paintLabel(self, painter, rect, tab, has_focus)
        if selected: 
              painter.restore()

QTabWidget_orig=qt.QTabWidget

class HighlightedTabWidget(QTabWidget_orig):
    """A QTabWidget equivalent which uses our HighlightedTabBar"""
    def __init__(self, parent, *args):
        QTabWidget_orig.__init__(self, parent, *args)
        self.setTabBar(HighlightedTabBar(self))
        
qt.QTabWidget=HighlightedTabWidget # monkey-patch the qt module to use this implementation

_______________________________________________
PyKDE mailing list    [email protected]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde

Reply via email to