user3315504
user3315504

Reputation: 1275

get the size of QGraphicsScene

I want to do the following:

  1. create a QGraphicsView
  2. connect it to QGraphicsScene
  3. Get the size of the QGraphicsScene
  4. create a QGraphicsRectItem with this size

My problem is how to get the size of the scene In all the examples I saw that they put constants in setSceneRect() The following is my code

class CharIdentifierInput(QDialog, Ui_CharIdentifierInput):
    """description of class"""
    def __init__(self, parent):
        QDialog.__init__(self, parent)
        self.setupUi(self)
        self.setFixedSize(self.width(), self.height()) 
        self.leftMouseButtonPressed = False
        self.createGui()

    def createGui(self):
        self.graphicsScene = QGraphicsScene()
        self.graphicsView.setScene(self.graphicsScene)

        # I want to replace this line with a line that sets to the actual scene size
        self.graphicsScene.setSceneRect(0,0,368,235)
        mainItem = MyQtCharIdentifierMain(self.graphicsScene.sceneRect())
        self.graphicsScene.addItem(mainItem)
        mainItem.setPos(0,0)

Upvotes: 1

Views: 5645

Answers (1)

a_manthey_67
a_manthey_67

Reputation: 4286

Getters of the dimensions of the sceneRect are QGraphicsScene.sceneRect(), QGraphicsScene.width() and QGraphicsScene.height()

if the sceneRect changes, QGraphicsScene.sceneRectChanged -signal is emitted, sendig the new sceneRect as parameter.

If QGraphicsView.setSceneRect() is not set, QGraphicsView.sceneRect() will return the same value as QGraphicsScene.sceneRect() and it changes with QGraphicsScene.sceneRect(), see documentation QGraphicsView and documentation QGraphicsScene

Upvotes: 2

Related Questions