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. Resizing and moving a QGraphicsItem
Forum Updated to NodeBB v4.3 + New Features

Resizing and moving a QGraphicsItem

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.8k Views 1 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.
  • X Offline
    X Offline
    xtraction
    wrote on last edited by
    #1

    Hello,

    I have a QGraphicsPathItem that I create after 'drawing' with the mouse on a scene. I have a background image in the scene and this path item gets created on top of the image which is almost transparent reflects a selection of an area of the underlying image. So basically I have my scene with two items.

    Now when I press the zoom button I don't actually do any transformations to my scene or view, I simply compute the appropriate image somewhere else and then replace the image to the zoomed one. But now I need the drawn image also to take into account the zoom level and when I scroll to also scroll accordingly. I was trying to do this getting the boundingRect of the item and calculate a new bounding rect according to zoom and scroll position and then setting that calculated rectangle to be the new bounding rectangle of my item, so my item would resize itself and move to the right position whether I zoom or scroll. But this is not the right way since it gives very strange behavior. I do all the prepareForGeometryChange() before setting the bounding rectangle which I set in a function like this:

    @
    QRectF PathItem::boundingRect() const
    {
    return m_rect;
    }

    void PathItem::setBoundingRect(QRectF rect)
    {
    prepareGeometryChange();
    m_rect = rect;
    update(m_rect);
    }
    @

    What would be the right way to do this? Basically how can I have an item in the scene move and rescale itself to a pre-calculated rectangle I provide it? Any hints and tips greatly appreciated.

    Thanks.

    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