Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Disabling QGraphicsScene's automatic focus

Disabling QGraphicsScene's automatic focus

Scheduled Pinned Locked Moved Solved Qt for Python
qt for python
3 Posts 2 Posters 645 Views
  • 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.
  • R Offline
    R Offline
    real_mithrandir
    wrote on last edited by
    #1

    Hi, I'm coding a simple PyQT5 application for a little university project. It is supposed to draw objects on a scene and allow you to apply geometric transformations to them. Almost everything works fine, except that the scene showing the objects is not supposed to move, even if one of its objects gets translated/rotated/scaled; every time I apply one transformation, the scene moves to the object's direction.

    I built the GUI using QtDesigner. That's it's basic structure (I suppressed some unrelated code):

    class Ui_MainWindow(object):
        def setupUi(self, MainWindow):
            # ...
            MainWindow.setGeometry(0,0,1111, 710)
            self.centralwidget = QtWidgets.QWidget(MainWindow)
            # ...
            self.shapesScene = QtWidgets.QGraphicsScene()
            self.shapesViewer = QtWidgets.QGraphicsView(self.centralwidget)
            # ...
    

    I instantiate the GUI in the main script like this:

    app = QtWidgets.QApplication([])
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    app.exec_()
    

    The objects are drawn in Ui_MainWindow.shapesScene using the methods addLine and addPolygon. Is there anyway I can set a static behavior to QGraphicsScene so that is keeps fixed?

    JonBJ 1 Reply Last reply
    0
    • R real_mithrandir

      Hi, I'm coding a simple PyQT5 application for a little university project. It is supposed to draw objects on a scene and allow you to apply geometric transformations to them. Almost everything works fine, except that the scene showing the objects is not supposed to move, even if one of its objects gets translated/rotated/scaled; every time I apply one transformation, the scene moves to the object's direction.

      I built the GUI using QtDesigner. That's it's basic structure (I suppressed some unrelated code):

      class Ui_MainWindow(object):
          def setupUi(self, MainWindow):
              # ...
              MainWindow.setGeometry(0,0,1111, 710)
              self.centralwidget = QtWidgets.QWidget(MainWindow)
              # ...
              self.shapesScene = QtWidgets.QGraphicsScene()
              self.shapesViewer = QtWidgets.QGraphicsView(self.centralwidget)
              # ...
      

      I instantiate the GUI in the main script like this:

      app = QtWidgets.QApplication([])
      MainWindow = QtWidgets.QMainWindow()
      ui = Ui_MainWindow()
      ui.setupUi(MainWindow)
      MainWindow.show()
      app.exec_()
      

      The objects are drawn in Ui_MainWindow.shapesScene using the methods addLine and addPolygon. Is there anyway I can set a static behavior to QGraphicsScene so that is keeps fixed?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @real_mithrandir
      While you await a better answer from someone who knows better than I... :)

      I think it may be the QGraphicsView you are seeing "moving", not the QGraphicsScene. The view is a QAbstractScrollArea, so is scrolling going on? Have a look at https://doc.qt.io/qt-5/qgraphicsview.html#sceneRect-prop, https://doc.qt.io/qt-5/qgraphicsview.html#transformationAnchor-prop, and other properties in QGraphicsView to do with scrolling/moving etc.?

      R 1 Reply Last reply
      1
      • JonBJ JonB

        @real_mithrandir
        While you await a better answer from someone who knows better than I... :)

        I think it may be the QGraphicsView you are seeing "moving", not the QGraphicsScene. The view is a QAbstractScrollArea, so is scrolling going on? Have a look at https://doc.qt.io/qt-5/qgraphicsview.html#sceneRect-prop, https://doc.qt.io/qt-5/qgraphicsview.html#transformationAnchor-prop, and other properties in QGraphicsView to do with scrolling/moving etc.?

        R Offline
        R Offline
        real_mithrandir
        wrote on last edited by
        #3

        @JonB the QGraphicsScene.setSceneRect totally worked for me. Thanks!

        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