Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue with fitInView of QGraphicsView when ItemIgnoresTransformations is on
    primarykey
    data
    text
    <p>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:</p> <pre class="lang-py prettyprint-override"><code>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_() </code></pre> <p>Any explanations will be appreciated!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload