How to create a smooth zooming effect in a QScrollArea?



  • I'm working on a PDF reader with PyQt4 and python-popplerqt4. PDF pages (QPixmaps) are displayed into QLables, laid out vertically in a QFrame. The QFrame is placed into QScrollArea.

    @
    QMainWindow
    |_ QScrollArea
    |_ QFrame (Document: stretch)
    |_ QLabel (Page: fixed size)
    | |_ QPixmap (stretch)
    |_ QLabel
    | |_ QPixmap
    |_ etc.
    @

    The size of the document is determined by the fixed size of the QLabels. The QPixmap is set to stretch accordingly and the QFrame around pages naturally adjusts its size.

    When I call for a zoom, pages (QLabels) are resized one by one with QLabel.setFixedSize(). The effect however is disappointing: resizing the document looks rickety and flickery. Zooming in Evince or Mendeley is really smooth in comparison.

    I have read elsewhere that calling QFrame.hide() before scaling and QFrame.show() after helps. Indeed it does for a small document. However, applied to a PDF of about 700 pages for instance, means a blank QScrollArea for more than a second. Not good.

    How can I scale the document in the QScrollArea and produce a smooth zoom effect?



  • 11 hours later...

    I've tried animating the the resizing of the pages with an animation set in the Page class (so each Page would have its own resize animation). But it didn't work at all---I mean the resizing didn't even take place. I've done animations before, so I'm pretty sure that should work. It gets me even more confused:

    @
    def applyScale(self):
    scale = self.display().scale() / 100
    size = self.source().pageSize() # size provided by Poppler.Page
    self.scale_animation = QtCore.QPropertyAnimation(self, "size")
    self.scale_animation.setDuration(200)
    self.scale_animation.setStartValue(self.size())
    self.scale_animation.setEndValue(QtCore.QSize(size.width() * scale, size.height() * scale))
    self.scale_animation.start()
    @



  • Apparently no simple solution, use QGraphicsView instead. See http://qt-project.org/forums/viewthread/17257/



  • Hello, I am attempting the almost-identical thing. Did you ever get a resolution (haha) to this problem? Thanks.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.