QGraphicsRectItem coordinate system on image resize
On an image(x by y), a QGraphicsRectItem is added, Let say Qrect(73, 77, 43, 28) Qrect(x,y,w,h). After resizing the image to 128 by 32, how this QGraphicsRectItem can be redrawn with proper co-ordinates.
The image is first resized, and then the graphicsRectItem to be added.
How a qrect can be mapped with respect to the image resized?
@sayan275 how do you add the rect item exactly?
You could add the rect item as a child of the image item for example and simply resize it to the parent boundingRect
I tried the following but didn't work out..
QGraphicsPixmapItem* item = new QGraphicsPixmapItem(QPixmap::fromImage(qImage, Qt::AutoColor)); m_ViewerScene->addItem(item); QGraphicsRectItem* rect = new QGraphicsRectItem(m_BoundingBox); m_ViewerScene->addItem(rect); rect->setParentItem(item); m_ViewerScene->update(); //add the resized QGraphicsPixmapItem to the pixmap item->setPixmap( item->pixmap().scaled(QSize(128, 32),Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); qInfo()<<"Rect resize props:::"<<item->childItems()->boundingRect(); m_BoundingBox = item->childItems()->boundingRect();
later I'm drawing box, on the image in an other viewer, with m_BoundingBox.
The grey area within the blue rectangle will be resized to 128 * 32, and then the red rectangle would be added on the resized image. How to get the co-ordinates of red rect on the resized image?