How to adjust the font color and size in PyQt5?
To set the font color and size, you can use the QFont object and QPalette object.
Firstly, create a QFont object and set the font size using the setPointSize() method.
font = QtGui.QFont()
font.setPointSize(12)
Next, create a QPalette object and use the setColor() method to set the font color.
palette = QtGui.QPalette()
palette.setColor(QtGui.QPalette.Text, QtCore.Qt.red)
Finally, apply the QFont object and QPalette object to the widget.
widget.setFont(font)
widget.setPalette(palette)
The complete sample code is shown below.
from PyQt5 import QtWidgets, QtGui, QtCore
app = QtWidgets.QApplication([])
widget = QtWidgets.QWidget()
font = QtGui.QFont()
font.setPointSize(12)
palette = QtGui.QPalette()
palette.setColor(QtGui.QPalette.Text, QtCore.Qt.red)
widget.setFont(font)
widget.setPalette(palette)
widget.show()
app.exec()
The code above sets the font size of the control to 12 and the color to red. You can modify the font size and color as needed.