Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8001521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:06:51+00:00 2026-06-04T16:06:51+00:00

I’m working on a PDF reader with PyQt4 and python-popplerqt4. PDF pages (QPixmaps) are

  • 0

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?

PS:
The images of the Poppler.Pages are drawn for the visible QLabel recipients only. i.e. resizing a document of 700 pages does not involve resizing as many images. It will in fact resize 2 to 4 images at the maximum (and the more, the less the resolution). Resizing the Document object then consists merely in resizing QLabels, for the most part empty.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:06:53+00:00Added an answer on June 4, 2026 at 4:06 pm

    After some investigation and some help from QtForums it appears there is no easy solution to do achieve the desired zoom effect with QScrollArea. Please prove me wrong otherwise.

    A better tool, though less easy to implement, is a QGraphicsView. It has a QGraphicsView.scale(float, float) method that does the zoom perfectly! It’s also much easier to use, since this scale method does not even require maintaining the content (except perhaps the resolution of images if you don’t load up hi-res from beginning onwards).

    QGraphicsScene however, the content of the QGraphicsView, is a bit more lazy and needs more work to set up, especially with regard to the layout. In my case, since I am working on a PDF viewer, I require images aligned vertically, which the QGraphicsLinearLayout can do.

    For the sake of posterity, here is an example code that shows how to implement pixmaps into a layout, into a scene into a view. It also shows, of course, how to scale the content.

    #!/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_())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.