self.boundingRect() give me dashed line dimensions shown in image. i need to get opaque area (where actual text is drawn)
I tried getting
self.opaqueArea()
but it returns QPainterPath object, which seems pretty complicated and apparently doesn't have width or height functions etc as its representation of complicated path objects. Q. Is there an easier way to calculate that. any ideas.. thanks in advance

print ("TEXT BOUNDING RECT:",self.boundingRect())
print ("TEXT OPAQUE AREA :",self.document().size())
print ("TEXT OPAQUE AREA BR size :",self.opaqueArea().boundingRect().size())
output:
TEXT BOUNDING RECT: PyQt5.QtCore.QRectF(0.0, 0.0, 590.0, 56.0)
TEXT OPAQUE AREA : PyQt5.QtCore.QSizeF(590.0, 56.0)
TEXT OPAQUE AREA BR size : PyQt5.QtCore.QSizeF()
QGraphicsTextIteminternally uses aQTextDocumentto manage the text. You can access this through.document(). The text document has a size property, which returns aQPointF.Unfortunately all the methods for this document return a standard rect of the bounding box. However, it is possible to make the text box re-adjust itself to the size of the text it contains. It doesn't quite get down to pixel level (due to line height padding) but it's close.
The above will give the following result —
The only other idea I had was to get a
QPainterPathfrom the text document and calculate thatQRect, but it doesn't appear to be easily accessible. One alternative would be to paint it to aQPainterand crop it there — but there is no built in cropping functionality in Qt.