How to change Maya UI text font color?

2.4k views Asked by At

I want to change the font color of a text in an UI, but it's seems that there is nothing in the text command doc to do this. It's possible to change the background color, but nothing about the font itself.

I searched around the internet and found this code to change a button text color using PyQt (source).

import maya.OpenMayaUI as omUI
from PyQt4 import QtGui
import sip
bt = sip.wrapinstance(long(omUI.MQtUtil.findControl(_the_button_name_)), QtGui.QPushButton)
bt.setStyleSheet('QPushButton {color: yellow}')

So, I have two questions:

First, what should I use, instead of QPushButton, to edit the color of a text control, and two, the button color here is changed to 'yellow' and I'd like to change it to a custom color value, is there a way to also do this?

Thanks in advance!

1

There are 1 answers

6
eyllanesc On BEST ANSWER

when using the setStyleSheet function you are changing the properties of the style with a syntax similar to CSS, so if we want to use a specific color we can pass the values as rgb or hex code as shown below:

pb.setStyleSheet('QPushButton {color: rgb(1, 1, 240)}')
pb.setStyleSheet('QPushButton {color: #0101F0}')

You can also apply to any widget without telling you to set the widget as shown below:

some_widget.setStyleSheet('color: #0101F0')

For text use the following:

lb = sip.wrapinstance(long(omUI.MQtUtil.findControl(_the_label_n‌​ame_)), QtGui.QLabel)
lb.setStyleSheet('color: #0101F0')