Text Color in QTabBar is not working

29 views
Skip to first unread message

kiteh

unread,
Jan 2, 2019, 7:19:20 PM1/2/19
to Python Programming for Autodesk Maya
Hi all,

I am trying to set text color to Red in a specified tab of QTabBar.
Tried using the command `setTabTextColor`, there is something happening but the text color is not changing, it is still remaining as white even when I put it at the __init__ stage.


I placed in a print statement in `set_menu()` as follows:
def set_menu(self):
   
....
   
# This will returns me PySide2.QtGui.QColor.fromRgbF(1.000000, 0.000000, 0.000000, 1.000000), values for Red
   
print self.tab_bar.tabTextColor(0)

Wondering if I have miss out something here?

Jakob Kousholt

unread,
Jan 2, 2019, 8:29:45 PM1/2/19
to python_inside_maya
Hey Kiteh,

You should be able to style all Qwidgets using the setStyleSheet function and color it with CSS.

setStyleSheet("color: #FF0000;")



Jakob Kousholt - Freelance Creature Modeler and Concept Sculptor
jak...@gmail.com
www.jakejk.com


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/2a378454-9f3a-4c96-a263-534616f0bb9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

kiteh

unread,
Jan 3, 2019, 6:51:37 PM1/3/19
to Python Programming for Autodesk Maya
Hi Jakob,

I am trying to target it to one or more tabs found within the QTabBar.
I asked about `setTabTextColor` as it was mentioned in http://pyqt.sourceforge.net/Docs/PyQt4/qtabbar.html#setTabTextColor

Even so, how should I incorporate the `setStylesheet` for the tabs? I have only used it eg. for QPushButton, QLabels etc, where they are mostly a singleton elements

Justin Israel

unread,
Jan 3, 2019, 7:45:41 PM1/3/19
to python_in...@googlegroups.com
The stylesheet reference explains how to style a QTabBar:
http://doc.qt.io/qt-5/stylesheet-reference.html#qtabbar-widget
 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

kiteh

unread,
Jan 16, 2019, 7:01:06 PM1/16/19
to Python Programming for Autodesk Maya
Currently I have tried using the following:

def tabs_color(self):
    ...
    ...

    for index in range(self.tab_bar.count()):
        text = self.tab_bar.tabText(index)
        color = QtCore.Qt.transparent.name if text in qmenu_items else QtCore.Qt.red.name
        # self.tab_bar.setTabTextColor(index, color)

        self.tab_bar.setStyleSheet(
            '''
            QTabBar::tab {{}}
            QTabBar::tab:selected {{background-color: {color};}}
            '''.format(color=my_color)
        )

There are 2 different issues that I am experiencing..

1. While the 'non-existent' tab(s) got highlighted with a red background, as soon as I try to navigate to all the other tabs, the supposed 'non-existent' tab reverted back to its original background color while my current tab selected instead got colored red.
2. Thought I had tried to use `setCurrentIndex` - navigate to each of the tab followed by setting using `setStylesheet`, no tabs will be highlighted and only the last tab will be considered?



Reply all
Reply to author
Forward
0 new messages