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

  • Home
  • SEARCH
  • 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 7041123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:00:00+00:00 2026-05-28T02:00:00+00:00

I have a short script that modifies an image with PIL several times. I

  • 0

I have a short script that modifies an image with PIL several times. I would like to be able to display the intermediate steps as it finishes with them, so I added a QGraphics Scene and I am trying to display the stages there. It will properly size and center the final stage (the last one posted before exiting the function), but it displays the intermediate steps without sizing or centering them.

The code to post the image is:

        #Code to generate the image and create the loop here...
        imgQ = ImageQt.ImageQt(img)
        pixMap = QtGui.QPixmap.fromImage(imgQ)

        scene = QtGui.QGraphicsScene()
        self.ui.previewGv.setScene(scene)
        pixMap = pixMap.scaled(self.ui.previewGv.size())
        #scene.clear()
        scene.addPixmap(pixMap)               
        self.ui.previewGv.repaint()
        self.ui.previewGv.show()

Is there some way to get it to properly display each stage?

  • 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-05-28T02:00:01+00:00Added an answer on May 28, 2026 at 2:00 am

    It is hard to determine your problem without loop code and working example. But i have similar test application, hope it will help.

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    import sys
    from PyQt4.QtCore import *
    from PyQt4.QtGui import *
    import Image
    import ImageQt
    import ImageEnhance
    import time
    
    class TestWidget(QWidget):
        def __init__(self, parent=None):
            QWidget.__init__(self, parent)
            self.scene = QGraphicsScene()
            self.view = QGraphicsView(self.scene)
            self.button = QPushButton("Do test")
    
            layout = QVBoxLayout()
            layout.addWidget(self.button)
            layout.addWidget(self.view)
            self.setLayout(layout)
    
            self.button.clicked.connect(self.do_test)
    
        def do_test(self):
            img = Image.open('image.png')
            enhancer = ImageEnhance.Brightness(img)
            for i in range(1, 8):
                img = enhancer.enhance(i)
                self.display_image(img)
                QCoreApplication.processEvents()  # let Qt do his work
                time.sleep(0.5)
    
        def display_image(self, img):
            self.scene.clear()
            w, h = img.size
            self.imgQ = ImageQt.ImageQt(img)  # we need to hold reference to imgQ, or it will crash
            pixMap = QPixmap.fromImage(self.imgQ)
            self.scene.addPixmap(pixMap)
            self.view.fitInView(QRectF(0, 0, w, h), Qt.KeepAspectRatio)
            self.scene.update()
    
    if __name__ == "__main__":
        app = QApplication(sys.argv)
        widget = TestWidget()
        widget.resize(640, 480)
        widget.show()
    
        sys.exit(app.exec_())
    

    The main points:

    • If you are doing some processing or sleep in loop, you need to call QCoreApplication.processEvents() to allow Qt to do updates.

    • I’m saving reference to ImageQt.ImageQt (self.imgQ) or it will crash.

    • As I understood, you are creating QGraphicsScene in each iteration, better solution to create it once and then call scene.clear().

    • Scaling pixmap just to display it sized and centered is expensive, QGraphicsView.fitInView() maked for this purpose.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a short version of the question: I start a thread like that:
I have written a short python script that opens Google music in web view
I have an AppleScript script that I use to display iTunes track information on
I have a short program that is used exclusively with a remote desktop connection
I have a short question. Im my current project I'm using LINQ-to-SQl. That is
Does anybody have a short code sample that can be run in the VS
So I have about 10 short css files that I use with mvc app.
I wrote a short script that never terminates. This script continuously generates output that
I have a PHP script that runs a SELECT query then immediately deletes the
I have a Haskell script that runs via a shebang line making use of

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.