1

In my project, I am using graphic units that consist of a QGraphicsItem which contains a QGraphicsTextItem. item_text is set to position (0,0) and its width is set to the width of the rect_item. In order to center the text in the center(horizontal), I use the html markup:

text_item->setHtml("<p align=\"center\">" + text + "</p>");

as a result i get: enter image description here

but i want to get: enter image description here

Do I need to manually calculate the text dimensions and the new text location coordinate in the parent element, or is there another way?

1 Answers1

0

You need to use QtextOption inside QGraphicsTextItem

Yanis600
  • 71
  • 9
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 04 '22 at 22:43