Tekst tekenen
Op deze pagina:
Tekenen kun je ook met tekst.
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtGui import QPainter, QColor, QFont
from PyQt5.QtCore import Qt
class Venster(QWidget):
def __init__(self):
super(Venster, self).__init__()
self.initUI()
def initUI(self):
# Ja, dit is hex!
self.text = u'\u0408\u0435 \u043d\u043e\u0435\u03dd\u0442 \u0578\u0456\u0435\u0442 \u0430\u0142\u0442\u0456\u0458\u0501 \u0410\u0405\u0421\u0406\u0406 \u0442\u0435 \u0121\u0435\u0432\u044f\u057d\u0456\u043a\u0435\u0578 \n \u043e\u043c \u0442\u043e\u0441\u043d \u0142\u0435\u0435\u0455\u0432\u0430\u044f\u0435 \u0442\u0435\u043a\u0455\u0442 \u0442\u0435 \u043a\u044f\u0456\u0458\u0121\u0435\u0578 \n \u0500\u0456\u0442 \u0456\u0455 \u0442\u043e\u0441\u043d \u043e\u043e\u043a \u0121\u043e\u0435\u0501 \u0142\u0435\u0435\u0455\u0432\u0430\u0430\u044f?'
self.setGeometry(400, 400, 340, 180)
self.setWindowTitle('Tekst tekenen')
self.show()
def paintEvent(self, event):
# Een Painter event staat altijd tussen een begin() en end()
qp = QPainter()
qp.begin(self)
self.drawText(event, qp)
qp.end()
def drawText(self, event, qp):
qp.setPen(QColor(45, 113, 75))
qp.setFont(QFont('Tahoma', 12))
qp.drawText(event.rect(), Qt.AlignCenter, self.text)
def main():
app = QApplication(sys.argv)
window = Venster()
sys.exit(app.exec_())
if __name__ == '__main__':
main()