There is a code snippet:

from PyQt5.Qt import * class Example(QWidget): def __init__(self): super(Example, self).__init__() self.initUi() def initUi(self): self.setStyleSheet('background : #7c7c7c') self.mainLayout = QVBoxLayout() self.b = QPushButton('Text') self.b.setStyleSheet('background : #000221; color: #ececec') self.b.setToolTip('Tooltip') self.mainLayout.addWidget(self.b) self.setLayout(self.mainLayout) app = QApplication([]) e = Example() e.show() app.exec() 

However, it does not work as I would like:

enter image description here

How to change the text color of the tooltip or its background?

    1 answer 1

    Try:

     from PyQt5.Qt import * class Example(QWidget): def __init__(self): super(Example, self).__init__() self.initUi() def initUi(self): # self.setStyleSheet('background : #7c7c7c') self.setStyleSheet(''' QWidget { background : yellow; } QPushButton { background : #aa0221; color: #ececec;} QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; } ''') self.mainLayout = QVBoxLayout() self.b = QPushButton('Text') # self.b.setStyleSheet('background : #aa0221; color: #ececec') self.b.setToolTip('Tooltip') self.mainLayout.addWidget(self.b) self.setLayout(self.mainLayout) app = QApplication([]) e = Example() e.show() app.exec() 

    enter image description here