Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphicsRectItem coordinate system on image resize
Forum Updated to NodeBB v4.3 + New Features

QGraphicsRectItem coordinate system on image resize

Scheduled Pinned Locked Moved Unsolved General and Desktop
qgraphicsitemqgraphicssceneresizemapto
3 Posts 2 Posters 1.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sayan275
    wrote on last edited by sayan275
    #1

    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?

    raven-worxR 1 Reply Last reply
    0
    • S sayan275

      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?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @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

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      S 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @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

        S Offline
        S Offline
        sayan275
        wrote on last edited by sayan275
        #3

        @raven-worx

        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()[0]->boundingRect();
                m_BoundingBox = item->childItems()[0]->boundingRect();
        

        later I'm drawing box, on the image in an other viewer, with m_BoundingBox.

        0_1527498444379_Untitled.png
        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?

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved