Another look at PyQT's canvas:
# pqt_drawtext2.py
# playing with PyQT's QPainter
# setPen, setBrush, setFont, drawRect and drawText
import sys
# simpler import
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class DrawText(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
# setGeometry(x_pos, y_pos, width, height)
self.setGeometry(300, 300, 350, 150)
self.setWindowTitle("Playing with PyQT's QPainter")
def paintEvent(self, event):
painter = QPainter()
painter.begin(self)
# PyQT has some color constants available
# give the canvas blue background color
painter.setBrush(QBrush(QColor("navy")))
painter.drawRect(event.rect())
# this will be the text color
painter.setPen(QColor("orange"))
# check the fonts available on your computer
# for instance in C:\WINDOWS\Fonts
painter.setFont(QFont('Comic Sans MS', 32))
# drawText (x, y, QString s)
painter.drawText(45, 90, "Hello World")
painter.end()
app = QApplication(sys.argv)
dt = DrawText()
dt.show()
app.exec_()