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. QGraphicsScene size increases twice at once when an item is movde to its left border...

QGraphicsScene size increases twice at once when an item is movde to its left border...

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 678 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.
  • kitekatK Offline
    kitekatK Offline
    kitekat
    wrote on last edited by
    #1

    I have a QGraphicsScene with a few movable items on it. When I drag an item to scene border, the size of the scene increases (it's okay, it should increase), and the scroll bars appear (that's okay too).

    But even if the moving item exceeds window borders a few pixels, scene size increases about twice at once, in one big leap.

    Here's a small demo (pardon my PyQt):

    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_())
    

    You should drag the squares to left border, and the size will increase twice at one moment when the item reaches window border.

    Cannot you tell me, how can I fix it?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Can you also give which version of PyQt5, Qt and OS you are using ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      kitekatK 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Can you also give which version of PyQt5, Qt and OS you are using ?

        kitekatK Offline
        kitekatK Offline
        kitekat
        wrote on last edited by
        #3

        @SGaist

        I use WIndows 7x64 and PyQt 5.8 (5.8.2, AFAIK).

        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