I have to create some Images as placeholder for articles which have no own images / pictures. I already realized this in python, but i want to write the code in a qt app again. The python code is working and it looks like this:
def createImage(text="Leer", pfad="", bildname="TextBild.jpg", colorname='red'):
offset = 20 # weisses Textfeld um diesen Offset grösser darstellen
bild = Image.new('RGB', (width, height), colorname)
draw = ImageDraw.Draw(bild)
font = ImageFont.truetype("cour.ttf", 20)
w,h = draw.textsize(text, font)
draw.rectangle((((width-w-offset)/2,(height-h-offset)/2),((width+w+offset)/2,(height+h+offset)/2)), fill='white')
draw.text(((width-w)/2,(height-h)/2),text,'black',font)
## print "Erzeuge: " + pfad + os.sep + bildname, "\nPfad:\t"+pfad, "\nBildname:\t"+bildname
bild.save(pfad + os.sep + bildname) if os.path.exists(pfad) else bild.save(bildname)
But how to do this in Qt? I know there is QImage, QPainter, etc. but I dont't find a example what ist useful. Perhaps I do a system call to create a Image with text out of a qt app.
The image looks like this:
Thanks in advance for every useful hint.