[Qt-interest] QGraphicsScene: get bounding box of selected items?

Roland Mueller roland.em0001 at googlemail.com
Mon Dec 27 10:55:15 CET 2010


Hello,

2010/12/27 <Oliver.Knoll at comit.ch>

> Hi,
>
> I am getting familiar with the QGraphicsScene API. Is there a method to get
> the bounding box of the selected items?
>
> This exists:
> http://doc.qt.nokia.com/latest/qgraphicsscene.html#itemsBoundingRect
>
> which gives me the bounding rect of /all/ items - is there an
> analogon/convenience method for getting the bounding rect of the /selected/
> items only?
>
>
> The purpose is that I want to render only the selected items into an image.
>
> Off course I can iterate over all rects as returned by
>
>  http://doc.qt.nokia.com/latest/qgraphicsscene.html#selectedItems
>

I'll neer tried that but according to the documentation it should be
possible to get the selectionArea() of the scene which returns an
QPainterPath object. The bounding rect should be then the boundingRect() of
the path:

   - QRectF boundingRectOfSelection =
   myScene.selectionArea().boundingRect();

QPainterPath <http://doc.qt.nokia.com/latest/qpainterpath.html>QGraphicsScene::selectionArea
() const

Returns the selection area that was previously set with
setSelectionArea<http://doc.qt.nokia.com/latest/qgraphicsscene.html#setSelectionArea>(),
or an empty QPainterPath
<http://doc.qt.nokia.com/latest/qpainterpath.html>if no selection area
has been set.

See also setSelectionArea<http://doc.qt.nokia.com/latest/qgraphicsscene.html#setSelectionArea>
().

QRectF <http://doc.qt.nokia.com/latest/qrectf.html>QPainterPath::boundingRect
() const

Returns the bounding rectangle of this painter path as a rectangle with
floating point precision.

Regards,
Roland

>
> and call http://doc.qt.nokia.com/latest/qrectf.html#united on their
> http://doc.qt.nokia.com/latest/qgraphicsitem.html#boundingRect, but I
> wonder whether I overlooked some convenience method somewhere in the Qt
> API...
>
> Cheers, Oliver
> --
> Oliver Knoll
> Dipl. Informatik-Ing. ETH
> COMIT AG - ++41 79 520 95 22
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101227/7cc3d6bf/attachment.html 


More information about the Qt-interest-old mailing list