0

having some trouble setting the color of the text in a QTabWidget. Wondering what I might be doing wrong here.

No luck per the example sited here

from PySide.QtGui import *
from PySide.QtCore import *

# QTabWidget
tab_widget = QTabWidget()
tab_a = QWidget()
tab_b = QWidget()
tab_widget.addTab(tab_a, 'tab_a')
tab_widget.addTab(tab_b, 'tab_b')
tab_widget.tabBar().setTabTextColor(0,Qt.red)
tab_widget.show()

The resulting text in the tabBar is just the standard white/gray.

Some other entries suggest subclassing QTabWidget may be necessary. Method number 2 shows a custom tab widget

# CUSTOM Tab Widget
class MyTabWidget(QTabWidget):
    def __init__(self):
        super(MyTabWidget,self).__init__()

    def setTabTextColor(self, ind, color):
        self.tabBar().setTabTextColor(ind, color)

tab_widget = MyTabWidget()
tab_a = QWidget()
tab_b = QWidget()
tab_widget.addTab(tab_a, 'tab_a')
tab_widget.addTab(tab_b, 'tab_b')
tab_widget.setTabTextColor(0,Qt.red)
tab_widget.show()

In both cases, my tab text color remains the default white/gray. Querying the color appears to show a change, but the visible color is still white/gray.

tab_widget.tabTextColor(0)
# Result: PySide.QtGui.QColor.fromRgbF(1.000000, 0.000000, 0.000000, 1.000000) #

Any ideas what I'm doing wrong here?

Thanks!

Ivan Kolesnikov
  • 1,787
  • 1
  • 29
  • 45
stowaway
  • 77
  • 9

0 Answers0