How to prevent scaling in QScrollArea due to the fact that it is so risky flickering?

I am working on a PDF reader with PyQt4 and python-popplerqt4. PDF pages (QPixmaps) are displayed in QLables, laid out vertically in a QFrame. QFrame is placed in 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 QLabels. The QPixmap is set to stretch, and the QFrame around the pages naturally adjusts its size.

When I invoke an increase, the pages (QLabels) change one by one with the help of QLabel.setFixedSize(). The effect, however, is disappointing: resizing the document looks shaky and flickering. Scaling in Evince or Mendeley is really smoothed by comparison.

, QFrame.hide() QFrame.show() . , . , PDF 700 , , QScrollArea . .

QScrollArea ?

PS: Poppler.Pages QLabel. 700 . 2 4 ( , ). QLabels, .

+3
1

QtForums , QScrollArea. , , .

, , QGraphicsView. QGraphicsView.scale(float, float), ! , ( , , , hi-res ).

QGraphicsScene QGraphicsView , . , PDF, , , <QGraphicsLinearLayout.

, , pixmaps , . , , .

#!/usr/bin/env python

import sys
from PyQt4 import QtGui, QtCore
from popplerqt4 import Poppler

class Application(QtGui.QApplication):

    def __init__(self):
        QtGui.QApplication.__init__(self, sys.argv)

        scene = QtGui.QGraphicsScene()
        scene.setBackgroundBrush(QtGui.QColor('darkGray'))
        layout = QtGui.QGraphicsLinearLayout(QtCore.Qt.Vertical)
        document = Poppler.Document.load('/home/test.pdf')
        document.setRenderHint(Poppler.Document.Antialiasing)
        document.setRenderHint(Poppler.Document.TextAntialiasing)
        for number in range(document.numPages()):
            page = document.page(number)
            image = page.renderToImage(100, 100)
            pixmap = QtGui.QPixmap.fromImage(image)
            container = QtGui.QLabel()
            container.setFixedSize(page.pageSize())
            container.setStyleSheet("Page { background-color : white}")
            container.setContentsMargins(0, 0, 0, 0)
            container.setScaledContents(True)
            container.setPixmap(pixmap)
            label = scene.addWidget(container)
            layout.addItem(label)

        graphicsWidget = QtGui.QGraphicsWidget()
        graphicsWidget.setLayout(layout)
        scene.addItem(graphicsWidget)
        self.view = View(scene)
        self.view.show()


class View(QtGui.QGraphicsView):

    def __init__(self, parent = None):
        QtGui.QGraphicsView.__init__(self, parent)

    def wheelEvent(self, event):

        if event.delta() > 0:
            self.scale(1.1, 1.1)
        else:
            self.scale(0.9, 0.9)

if __name__ == "__main__":
        application = Application()
        sys.exit(application.exec_())
+4

All Articles