from PySide2.QtGui import QPainter, QFont # create a QPainter object painter = QPainter() # set the font font = QFont("Helvetica", 12) painter.setFont(font)
from PySide2.QtGui import QPixmap, QPainter, QFont # create a QPixmap object to draw on pixmap = QPixmap(100, 100) pixmap.fill() # create a QPainter object to draw on the pixmap painter = QPainter(pixmap) # set the font of the QPainter object font = QFont("Arial", 16) painter.setFont(font) # draw some text on the pixmap painter.drawText(20, 50, "Hello, world!") # release the QPainter object painter.end()This example creates a QPixmap object and a QPainter object to draw on it. The font of the QPainter object is set to Arial with a size of 16 points, and some text is drawn on the pixmap at position (20, 50). Package library: PySide2.QtGui.