title: How to keep the size and position of QGraphicsItem when scaling the view?
body: <p>I have some QGraphicsItems in the QGraphicsScene which should keep the same size and position when scaling. I've tried QGraphicsItem::ItemIgnoresTransformations but it turns out that the items get wrong positions. Below is a sample code:</p>
  
  <p>I have subclassed QGraphicsView like this:</p>
  
  <pre><code>class Graphics : public QGraphicsView
  {
  public:
      Graphics();
      QGraphicsScene *scene;
      QGraphicsRectItem *rect;
      QGraphicsRectItem *rect2;
  
  protected:
      void wheelEvent(QWheelEvent *event);
  };
  </code></pre>
  
  <p>And in its constructor:</p>
  
  <pre><code>Graphics::Graphics()
  {
      scene = new QGraphicsScene;
      rect = new QGraphicsRectItem(100,100,50,50);
      rect2 = new QGraphicsRectItem(-100,-100,50,50);
      scene-&gt;addLine(0,200,200,0);
  
      rect-&gt;setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
      scene-&gt;addItem(rect);
      scene-&gt;addItem(rect2);
  
      setScene(scene);
      scene-&gt;addRect(scene-&gt;itemsBoundingRect());
  }
  </code></pre>
  
  <p>The wheelEvent virtual function:</p>
  
  <pre><code>void Graphics::wheelEvent(QWheelEvent *event)
  {
      if(event-&gt;delta() &lt; 0)
          scale(1.0/2.0, 1.0/2.0);
      else
          scale(2, 2);
      scene-&gt;addRect(scene-&gt;itemsBoundingRect());
  
      qDebug() &lt;&lt; rect-&gt;transform();
      qDebug() &lt;&lt; rect-&gt;boundingRect();
      qDebug() &lt;&lt; rect2-&gt;transform();
      qDebug() &lt;&lt; rect2-&gt;boundingRect();
  }
  </code></pre>
  
  <p>orginal view looks like this:
  <a href="https://i.stack.imgur.com/95TPq.png" rel="nofollow noreferrer">1</a></p>
  
  <p>take the line as road and rect aside as a symbol. When zoomed out, the rect maintain its size but jumps out of the scene:
  <a href="https://i.stack.imgur.com/2iLKj.png" rel="nofollow noreferrer">2</a></p>
  
  <p>which should be that topleft of rect to middle of line. I'm also confused with debug info showing that the boundingRect and transform stays the same, which seems that nothing has changed! What causes the problem and is there any way to solve it? Could  someone help? Thank you!</p>