[PyQt] QGrahics / textItemSize

KONTRA, Gergely pihentagy at gmail.com
Wed Feb 9 13:32:00 GMT 2011


Maybe because you set the font size in POINTs.

See: http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qfont.html#QFont-2

and also

http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qfont.html#setPixelSize
+-[ Gergely Kontra <pihentagy at gmail.com> ]------------------+
|                                                           |
| Mobile:(+36 20)356 9656                                   |
|                                                           |
+- "Olyan lángész vagyok, hogy poroltóval kellene járnom!" -+



On Sun, Feb 6, 2011 at 16:54, Philippe Crave <philippe.crave at gmail.com> wrote:
> Thanks for testing !
>
> I attach a new code with Arial (maybe you're under windows) and a new png.
> this time, I also draw a rectangle. 200x40px, red.
>
> you can check that the scene produced my the pyqt code gives a rectangle
> like the one in the png. I did it in inkscape. a 200x40px red rect.
>
> but for the font, "hello 1" is too big. "hello 2" seems to be of similar
> size. but it was scale.
> I attach the .svg too.
> in the svg (and the png), i wrote "hello" in arial/40
>
> why should I scale the text (with a ratio of .75) to get a correct size ?
>
> 2011/2/6 KONTRA, Gergely <pihentagy at gmail.com>
>>
>> For me the 2 texts are sized equal if I remove the line, which scales the
>> text.
>>
>> But I guess I do not have the font Norasi (rendered as some
>> sans-serirf font on my PC).
>>
>> Gergo
>> +-[ Gergely Kontra <pihentagy at gmail.com> ]------------------+
>> |                                                           |
>> | Mobile:(+36 20)356 9656                                   |
>> |                                                           |
>> +- "Olyan lángész vagyok, hogy poroltóval kellene járnom!" -+
>>
>>
>>
>> On Sat, Feb 5, 2011 at 11:14, Philippe Crave <philippe.crave at gmail.com>
>> wrote:
>> > Hello,
>> >
>> > When I add to the Scene some rectangles and texts, rectangles are
>> > perfect,
>> > but text are too big.
>> >
>> > If I add a QGraphicsSimpleTextItem with a font_size of 40, it will
>> > display
>> > bigger than the same text/font/size if I draw it in inkscape (or
>> > anywhere
>> > else).
>> > Seems that I have to scale with a ratio of 0.75 to get a correct size.
>> >
>> > What am I doing wrong ?
>> >
>> > here is my sample (I also attach a png with a text in Norasi with a size
>> > of
>> > 40):
>> >
>> > from PyQt4 import QtGui
>> >
>> > import sys
>> >
>> > app = QtGui.QApplication(sys.argv)
>> >
>> > scene = QtGui.QGraphicsScene(0, 0, 400, 400)
>> >
>> > scene.addSimpleText('HELLO 1', QtGui.QFont('Norasi', 40))
>> >
>> > t = scene.addSimpleText('HELLO 2', QtGui.QFont('Norasi', 40))
>> >
>> > t.setY(100)
>> >
>> > t.scale(.75, .75)
>> >
>> > view = QtGui.QGraphicsView(scene)
>> >
>> > view.setRenderHint(QtGui.QPainter.Antialiasing)
>> >
>> >
>> > view.setViewportUpdateMode(QtGui.QGraphicsView.BoundingRectViewportUpdate)
>> >
>> > view.show()
>> >
>> > sys.exit(app.exec_())
>> >
>> >
>> >
>> > _______________________________________________
>> > PyQt mailing list    PyQt at riverbankcomputing.com
>> > http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>> >
>
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>


More information about the PyQt mailing list