Qt World Summit: Submit your Presentation

[Solved] Making a QRect that surrounds other QRects

  • Is there a quick way to create a QRect that surrounds other, specified, QRect items?

    Context: I have to implement the boundingRect() method in a QGraphicsItem class. The class contains two things: A QPainterPath for a symbol and a QRect for text that goes next to the symbol. In the boundingRect() method I need to return a QRect that surrounds the two.

    Do I need to calculate the position and the size of the rectangle manually or is there some easy magic way of doing this?

  • @Joel-Bodenmann said:

    QRectF QRectF::united ( const QRectF & rectangle ) const

  • @Joel-Bodenmann said:
    Just do not be confused. You need QRectF not QRect
    virtual QRectF boundingRect () const = 0

  • That's exactly what I have been looking for! I definitely searched for the wrong terms.
    Thank you for your help. Very appreciated.