我绘制文本,问题是如何导入自定义字体(tff文件与脚本文件在同一文件夹中)并更改字体。 这是代码:
def paintEvent(self, e):
painter = QtGui.QPainter(self)
painter.setRenderHint(painter.Antialiasing)
self.drawText(e, painter)
super(SpeedPrg, self).paintEvent(e)
def drawText(self, event, qp):
qp.setPen(QtGui.QColor(255,255,255))
qp.drawText(event.rect(), QtCore.Qt.AlignCenter, str(self.setText))
答案 0 :(得分:3)
您可以使用以下代码:
# Load the font:
font_db = QFontDatabase()
font_id = font_db.addApplicationFont("your_font.ttf")
# families = font_db.applicationFontFamilies(font_id)
your_ttf_font = QFont("one of your font families")
# tell painter to use your font:
qp.setFont(your_ttf_font)