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

QGraphicsView::centerOn changes scrollbars but not transform

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P3: Somewhat important
    • Resolution: Unresolved
    • Affects Version/s: 5.14.1
    • Fix Version/s: None
    • Component/s: Widgets: GraphicsView
    • Labels:
      None
    • Environment:
      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

            Assignee:
            bibr Andreas Aardal Hanssen
            Reporter:
            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