Nominate our 2022 Qt Champions!

Creating a QGraphicsTextItem that "follows" a QGraphicsItem

  • I don't know if there is already a function for this, but what i want to do is:

    when i click on the diagramscene i want it to add 2 items, one QGraphicsSvgItem and one QGraphicsTextItem, but here is the deal, when i drag and drop my QGraphicsSvgItem i want the QGraphicsTextItem to keep it up with position, kind of following him, in a same position towards the QGraphicsSvgItem.

    How can I do this?

  • Lifetime Qt Champion

    See :

    "Items can contain other items, and also be contained by other items. All items can have a parent item and a list of children. Unless the item has no parent, its position is in parent coordinates (i.e., the parent's local coordinates). Parent items propagate both their position and their transformation to all children."
    So make one the parent of the other.

Log in to reply