Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8642263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:43:54+00:00 2026-06-12T11:43:54+00:00

While trying to implement a scene where item sizes do not change but distances

  • 0

While trying to implement a scene where item sizes do not change but distances between items get magnified I encountered this problem with the following code which draws a rectangle and the text “A”. Now if I set the flag ItemIgnoresTransformations on the rectangle item, zooming in causes the rectangle to vanish (click and drag mouse button around the rectangle). But that does not happen in case of the text. Also, the new viewport area set by fitInView is very different for I asked for:

import sys
from PyQt4 import QtCore, QtGui

class GV(QtGui.QGraphicsView):
    def __init__(self, *args, **kwargs):
        QtGui.QGraphicsView.__init__(self, *args, **kwargs)

    def mousePressEvent(self, event):
        pos = QtCore.QPoint(event.pos())
        self.startPos = pos

    def mouseReleaseEvent(self, event):
        pos = QtCore.QPoint(event.pos())
        self.endPos = pos
        rect = QtCore.QRect(self.startPos, self.endPos) 
        sceneRect = self.mapToScene(rect).boundingRect()
        print 'Selected area: viewport coordinate:', rect, \
            ', scene coordinate:', sceneRect
        self.fitInView(sceneRect)
        print 'new viewport in scene coordinates:', \
            self.mapToScene(self.viewport().geometry()).boundingRect()

class Scene(QtGui.QGraphicsScene):
    def __init__(self, *args, **kwargs):
        QtGui.QGraphicsScene.__init__(self, *args, **kwargs)    
        self.itemA = QtGui.QGraphicsSimpleTextItem('A')
        self.itemA.setPos(20, 20)
        self.itemA.setFlag(QtGui.QGraphicsItem.ItemIgnoresTransformations, True)
        self.addItem(self.itemA)
        self.itemB = QtGui.QGraphicsRectItem(30, 50, 20, 20)
        self.addItem(self.itemB)
        self.itemB.setFlag(QtGui.QGraphicsItem.ItemIgnoresTransformations, True)

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    widget = QtGui.QMainWindow()
    scene = Scene()
    view = GV(scene, widget)
    widget.setCentralWidget(view)
    widget.show()
    app.exec_()

Any explanations will be appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:43:55+00:00Added an answer on June 12, 2026 at 11:43 am

    In fact, the rectangle does not vanish. But it moves around “strangely”.

    self.itemB = QtGui.QGraphicsRectItem(30, 50, 20, 20)
    

    This line may not be what you want. This creates an item and puts a rectangle/square starting from (30, 50) in local coordinates. Then you add this to the scene. This gives you an item anchored at (0, 0), spans up to (50, 70) but draws a rectangle only in the bottom right 20x20.

    When you set ItemIgnoresTransformations, item can’t do its regular transformations in case of a zoom. Scene zooms in, for item to ignore this transformation, it kind of “shrinks” itself. But it’s still anchored at (0, 0) and the rectangle is at the bottom-right, so the drawn rectangle moves toward the upper-left.

    Solution is rather simple. Don’t create your rectangle in local coordinates, i.e. your rectangle should start from (0, 0) and you should position it explicitly. Which translates to this:

    self.itemB = QtGui.QGraphicsRectItem(0, 0, 20, 20)
    self.itemB.setPos(30, 50)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

while i am trying to implement font menu item in notepad , im not
I am trying to implement the adaptive huffman code, but while trying to build
Basically while trying to implement a graph through adjacency list, I get stucked defining
I am trying to implement a custom OpenGL scene (wrapped in a QGLWidget), but
I'm trying to implement a simple drag/drop of images between panels using jQuery. While
While trying to implement an MVC file upload example on Scott Hanselman's blog. I
I'm new to AS3 and I'm getting this error while trying to implement OO
While trying to implement the second answer to a previous question , I am
I am received the following error while trying to implement a C# extension function
I recently ran across this problem while trying to implement a service that has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.