Mahmoud Hassan
Mahmoud Hassan

Reputation: 608

Draw the dimensions on QGraphicsItem

I'm drawing a QGraphicsPolygonItem like this:

enter image description here

I need to have the dimensions information on the scene, like this:

enter image description here

I'm using QGraphicsPolygonItem, QGraphicsScene and QGraphicsView.

Upvotes: -1

Views: 329

Answers (1)

TheDarkKnight
TheDarkKnight

Reputation: 27611

There are several ways to achieve what is being asked here.

Personally, I'd opt for not using a QGraphicsPolygonItem, but creating a class derived from QGraphicsItem. This class would store a QPolygonF to store the required points. Then you'd overload the following functions:-

  • boundingRect
  • shape
  • paint

In the paint function the class draws the polygon and all the dimensions with it.

Alternatively, you could create separate QGraphicsItem classes for just the dimensions, set their parent as the QGraphicsPolygonItem and then set their positions, but this can get a bit messy.

Upvotes: 1

Related Questions