Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-82658

QGraphicsView::centerOn changes scrollbars but not transform

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.14.1
    • Widgets: GraphicsView
    • None
    • probably all. I use archlinux with pyside 5.14.1, python 3.8

    Description

      When calling QGraphicsView::centerOn(QPointF) it will modify the horizontal and vertical scroll bars. It does not however sync the viewport transform. As such it becomes 'out of sync'.

      Below a pyside2 script that illustrates the problem: 

      pixmapitem = QGraphicsPixmapItem()
      
      pixmapitem.setPixmap(...)
      
      view.scene().addItem(pixmapitem)
      
      print(view.transform())
      
      view.fitInView(pixmapitem, Qt.KeepAspectRatioByExpanding)
      
      print(view.transform()) # unchanged wrt previous print
      
       
      
      

       

      Expected behavior: both scrollbars and the transform is updated.

       

      A possible solution could be the following 'code' for centerOn that will modify the transform.

      QGraphicsView::centerOn(QPointF center)
      {
         current_center = mapToScene(viewport().rect().center());
         translate(current_center.x() - center.x(), current_center.y() - center.y());
      }

       This will also update the scrollbars via centerView call in setTransform.

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            bibr Andreas Aardal Hanssen
            kees Kees
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes