Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QGraphicsTextItem of unit dimension i.e. corresponding to unit rect i.e. a primitive so can be dragged out from one pixel size.
bootchk last edited by
I want a "primitive" QGraphicsTextItem of unit dimension that corresponds to a primitive QGraphicsRectItem having rect (0,0,1,1). (I call them glyphs. Usually a glyph means a primitive text character, a letter, that composes into words.) The user will drag out (rubberband) these shapes. Here, the primitive unit text item may have no contents or may have for example prototype text (to the user) such as "abc". Dragging them out simply scales them up from their unit size.
I am having difficulty. I am setting font, and setting the pointSize of the font. It appears that I also need to set the margin of the underlying QTextDocument. One symptom is that the text appears much below and to the right of the cursor position (corresponding to the margin?) What are the units of QTextDocument.setDocumentMargin()? I am quessing that they are "characters".
Another symptom is that the prototype text "abc" is rendered garbled, one character on top of another. I suppose I need to call QTextGraphicsItem.setTextWidth() with a reasonable value, say 12 (the user would want an initial text box to hold that many characters.) Note textWidth might better be called textWrappingWidth and is in units of characters also?
I suppose that for a textWidth of say 3 characters, and points per pixel of say 1, I need to setPointSize of the unit textitem at approximately 1/3. More precisely I need to use font metrics since characters are usually less wide than tall.
I would appreciate a reference to sample code. It should be a common idea.