4

I am scaling a QGraphicsItem in some parts of the my pyqt code. In another section of my code when I call self.rect.adjusted(0, 0, 0, 0) it returns the dimensions before transformation. My question is how can I find the dimensions after transformation?

2 Answers 2

5

After the transformation can ask for the sceneBoundingRect () or call boundingRegion () that is used for greater precision than boundingRect (). This function is in QGraphicsItem. In the QtAssistant you can read more about that:

The bounding region describes a coarse outline of the item's visual contents. Although it's expensive to calculate, it's also more precise than boundingRect(), and it can help to avoid unnecessary repainting when an item is updated. This is particularly efficient for thin items (e.g., lines or simple polygons). You can tune the granularity for the bounding region by calling setBoundingRegionGranularity(). The default granularity is 0; in which the item's bounding region is the same as its bounding rect. itemToDeviceTransform is the transformation from item coordinates to device coordinates. If you want this function to return a QRegion in scene coordinates, you can pass sceneTransform() as an argument.

0

i've also had this question but didn't get answer.

suppose you have a QGraphicsPixmapItem use sceneBoundingRect() to get a QrectF where you can retreive the width() and height()

Each time you scaled an object call this function to get the values

With this you gona get also the position in the scene of your object

Hope that help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.