PyQt5: What does the param "Union" mean in a method signature?

1.1k views Asked by At

For example:

self.content_text = QtWidgets.QTextEdit(self.tab_2)
self.content_text.setTextColor( ? )

The params are:

(self, Union, QColor=None, Qt_GlobalColor=None, QGradient=None)

What is Union? Which value should I type in?

1

There are 1 answers

1
ingvar On

Method setTextColor has following prototype (from QTextEdit.py):

def setTextColor(self, Union, QColor=None, Qt_GlobalColor=None, QGradient=None):
    """ setTextColor(self, Union[QColor, Qt.GlobalColor, QGradient]) """
    pass

Union here is typing.Union, that used for type hints. Union[QColor, Qt.GlobalColor, QGradient] means "parameter with type QColor or Qt.GlobalColor or QGradient". For some reason it appears in params list too while docstring setTextColor(self, Union[QColor, Qt.GlobalColor, QGradient]) is correct. In your program use this method like

self.content_text.setTextColor(QtGui.QColor(124, 124, 134))