How to add a text label with every shape I draw using QPainter
-
wrote on 29 Jun 2022, 03:08 last edited by BigBen
Hi.
I am drawing several shapes (rectangles, lines, ellipse...) on a label (QLabel) using QPainter. This is working fine.
However, now I want to add a title/label for each shape I draw after I am done drawing it. So, when I finish drawing a shape, a title (line 1, line 2, rectangle 1, etc. ) for that shape should appear anywhere near the body of that shape.I am not able to understand how to achieve this.
-
Hi.
I am drawing several shapes (rectangles, lines, ellipse...) on a label (QLabel) using QPainter. This is working fine.
However, now I want to add a title/label for each shape I draw after I am done drawing it. So, when I finish drawing a shape, a title (line 1, line 2, rectangle 1, etc. ) for that shape should appear anywhere near the body of that shape.I am not able to understand how to achieve this.
-
wrote on 29 Jun 2022, 06:28 last edited by
Hi.
I am not drawing the labels yet, as I have no idea how to achieve that.
The relevant code for drawing the shapes is as follows:
All this is in one function.QPainterPath* ThePath = myShape->myQPainterPath(); myPen.setColor(myShape->color()); myPen.setWidth(myShape->thickness()); myPen.setStyle(myShape->style()); thisPainter.setPen(myPen); thisPainter.drawPath(*ThePath);
-
Hi,
What is the goal of your application ?
Depending on that you can either draw the text at the same time as the path or maybe consider using the Graphics View Framework and use different items for the paths and the labels.
-
wrote on 24 Aug 2022, 12:50 last edited by
I'm using QPainter to draw various forms (rectangles, lines, ellipses, etc.) on a label (QLabel). Everything is going well.
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. -
wrote on 1 Oct 2022, 11:15 last edited by
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
Do you have a question on how to draw some text near the lines of your shapes or is that ok now? -
wrote on 19 Oct 2022, 10:29 last edited by
@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. -
wrote on 3 Jun 2024, 13:59 last edited byThis post is deleted!