Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[~Solved] Set Alignment in QGraphicsTextItem?
How do I properly align a multi-line text in a QGraphicsTextItem?
The text seems to be always left-aligned, despite specifying
@ QTextOption option = pTextItem->document()->defaultTextOption();
I have also tried assigning an alignment to all text blocks - no effect.
Edit: I only use plain text. I have found "this Bug":https://bugreports.qt-project.org/browse/QTBUG-312 regarding html text.
Just a question, do you set the option before or after setting the text ?
I've tried setting the default text alignment
- when the object is created (when text is still empty)
- on every contentsChanged() signal
I've tried setting the text alignment for all text blocks
- whenver the block count changes
Any other places I should try?
I would also do it in the constructor. As a workaround, did you try to resize the item as suggested in the bug report ?
It seems, the alignment only works if the document's textWidth is set.
I expected it to work without the text width, based on the length of the longest text line.