B
B
Bunny Fluffy2017-04-20 18:44:03
Python
Bunny Fluffy, 2017-04-20 18:44:03

QGraphicsScene: Why does the size double when an element is dragged to the border?

I have, brothers, a QGraphicsScene with several objects on it. And when I drag them with the mouse, when the left edge of the screen is reached, the scene not only increases in size (which is correct), but increases damn strongly (almost twice) and abruptly (which is not good).
Here is a small demo (there you need to drag one of the squares to the left edge of the screen).

import sys

from PyQt5 import QtWidgets, QtGui, QtCore
from PyQt5.QtWidgets import QGraphicsItem, QGraphicsTextItem, QGraphicsRectItem

if __name__ == "__main__":

    #########################################
    sys._excepthook = sys.excepthook
    def exception_hook(exctype, value, traceback):
        sys._excepthook(exctype, value, traceback)
        sys.exit(1)
    sys.excepthook = exception_hook
    ##########################################



    app = QtWidgets.QApplication(sys.argv)

    view = QtWidgets.QGraphicsView()
    view.setRenderHint(QtGui.QPainter.Antialiasing)
    view.setMouseTracking(True)
    view.setDragMode(QtWidgets.QGraphicsView.RubberBandDrag)

    scene = QtWidgets.QGraphicsScene()

    rect_item = QGraphicsRectItem(-50, -50, 100, 100)
    rect_item.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable | QGraphicsItem.ItemIsMovable)
    scene.addItem(rect_item)


    rect_item2 = QGraphicsRectItem(-50, -50, 100, 100)
    rect_item2.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable | QGraphicsItem.ItemIsMovable)
    scene.addItem(rect_item2)

    rect_item2.setPos(-120, -120)

    view.setScene(scene)
    view.showMaximized()

    sys.exit(app.exec_())

I have to ask: how can I overcome this?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question