How to add a text label with every shape I draw using QPainter
-
Now I want to give each form I design a title or label after I finish sketching it. As a result, whenever I'm done sketching a form, its title (such as line 1, line 2, rectangle 1, etc.) ought to be visible somewhere close to the shape's body.
-
Now I want to give each form I design a title or label after I finish sketching it. As a result, whenever I'm done sketching a form, its title (such as line 1, line 2, rectangle 1, etc.) ought to be visible somewhere close to the shape's body.
@adamarehart
Is there a question hidden there ? -
@Birdwell
Next to where you callthisPainter.drawPath(*ThePath);to draw the shape callthisPainter.drawText(...)You will need to set the point or rectangle where you want the text based on the point/rectangle where you are drawing the shape. You will want to adjust from that one to be somewhere a bit outside it so that your text does not write onto the shape. -
This post is deleted!
-
To label your shapes, store each object's geometry and title in a custom list of structs. Inside your paintEvent(), iterate through this list to render your shapes.
Immediately after drawing a shape, use painter.drawText() to render its title. Calculate the text position using the shape’s bounding coordinates (like rect.topLeft()) with a small vertical offset, ensuring labels appear consistently near the body of each shape.
-
Is there any question related to draw some text near the lines of your shape?
-
This post is deleted!
-
J JKSH locked this topic on