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. Update QGraphicsScene only in a specified area
Qt 6.11 is out! See what's new in the release blog

Update QGraphicsScene only in a specified area

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 399 Views 2 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.
  • T Offline
    T Offline
    Thomas Stein
    wrote on last edited by Thomas Stein
    #1

    Hi,
    I've been struggling with this for a while now.
    I have a QGraphicsView and in it a QGraphicsScene. At runtime I am trying to update only specific areas in the QGraphicsScene but it doesnt quiet work. Here is some minimal code showing the problem:

    import sys
    from PyQt5 import QtWidgets as qtw
    from PyQt5 import QtGui as qtg
    from PyQt5 import QtCore as qtc
    
    class MainWindow(qtw.QMainWindow):
        def __init__(self):
            super().__init__()
            self.scene = qtw.QGraphicsScene()
            self.scene.setSceneRect(0,0,720,720)
            self.view = qtw.QGraphicsView()
            self.view.setViewportUpdateMode(qtw.QGraphicsView.NoViewportUpdate)
            self.view.setScene(self.scene)
            self.setCentralWidget(self.view)
            self.show()
    
        def mousePressEvent(self, a0: qtg.QMouseEvent) -> None:
            self.scene.addLine(0, 0, 720, 720)
            self.scene.update(0, 0, 720, 720)     #<--- This does not work but should work
            #self.scene.update()                <--- This works for some reason
    
    if __name__ == '__main__':
        app = qtw.QApplication(sys.argv)
        mainWindow = MainWindow()
        sys.exit(app.exec())
    

    For some reason, calling update() without parameter on the scene object works, but when i specify the area to be updated, it doesnt work. Any ieads?

    Note: I set the views viewportupdatemode to NoViewportUpdate because the docs state the following:
    QGraphicsView will never update its viewport when the scene changes; the user is expected to control all updates. This mode disables all (potentially slow) item visibility testing in QGraphicsView, and is suitable for scenes that either require a fixed frame rate, or where the viewport is otherwise updated externally.

    This is what I want, since i only want to update specific areas almost every frame, not the whole scene over and over again. When is set the Viewportmode to something else, it seems like update() calls on the QgraphicsScene object within the QGraphicsView are being ignored

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

      Hi,

      Please don't post the same question multiple times.

      Duplicate

      Closing this one

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

      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