How to keep rectangle name to its center ?
Unsolved
General and Desktop
-
I have a QGraphicsScene that contains rectangle.
I know rectangles top left and bottom right x and y co-ordinates.
I want to place name of rectangle such that, half name will come to left half of rectangle and half will come to right half of rectangle.LIke this :
I tried this way :
QFontMetrics fontMetrics(QApplication::font()); int textWidth = fontMetrics.width(instanceTextString) / 2; // Half of the name width int textHeight = fontMetrics.height() ; int rectWidthMidPoint = (x2 - x1 ) / 2; int textStartXPoint = rectWidthMidPoint - textWidth; int textStartYPoint = y1 - textHeight; text->DrawText(textStartXPoint ,textStartYPoint );
But name position is far to the left.
How to solve it ?