Qt World Summit: Register Today!

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?

  • Moderators

    @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

  • @raven-worx

    I tried the following but didn't work out..

            QGraphicsPixmapItem* item = new QGraphicsPixmapItem(QPixmap::fromImage(qImage, Qt::AutoColor));
            QGraphicsRectItem* rect = new QGraphicsRectItem(m_BoundingBox);
            //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()[0]->boundingRect();
            m_BoundingBox = item->childItems()[0]->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?