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 8918503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:46:06+00:00 2026-06-15T05:46:06+00:00

I have a PyQt4 program with widgets whose content redraws very slowly (it’s ok,

  • 0

I have a PyQt4 program with widgets whose content redraws very slowly (it’s ok, because of my tasks). And when I trying to resize those widgets, program is trying to redraw a lot of times while mouse is not released. That’s a lot of freezes.

I want to disable that auto-redrawing and configure PyQt to redraw all widgets only when mouse is released (which means that redraw happens exactly one time per one resize).

How to do that?

Edit1. I’ll see it quite simply, like this: you drag the line, and while you dragging, all widgets stand. When you release it, widgets redrawing. But I’m really not sure that it’s possible in PyQt4.

  • 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-15T05:46:07+00:00Added an answer on June 15, 2026 at 5:46 am

    First, I would recommend making sure that if you are using custom paint events with your widgets, that you are not doing too heavy of work in each event and simply looking for a band-aid solution. If this is the case, try and find a way to cache or reduce the work. Otherwise…

    The decision to draw opaque or not is one made by the window manager of your platform. As far as I know, there is not a simple attribute to toggle this feature. Something similar to this exists on a QSplitter to only draw after the handle is released.

    I can offer one workaround approach, which is to delay the update until after no resize has occurred for a period of time. This will give your application some breathing room to reduce the paint events.

    from PyQt4 import QtCore, QtGui
    import sys
    
    class DelayedUpdater(QtGui.QWidget):
    
        def __init__(self):
            super(DelayedUpdater, self).__init__()
            self.layout = QtGui.QVBoxLayout(self)
            self.label = QtGui.QLabel("Some Text")
            self.layout.addWidget(self.label, QtCore.Qt.AlignCenter)
    
            self.delayEnabled = False
            self.delayTimeout = 100
    
            self._resizeTimer = QtCore.QTimer(self)
            self._resizeTimer.timeout.connect(self._delayedUpdate)
    
        def resizeEvent(self, event):
            if self.delayEnabled:
                self._resizeTimer.start(self.delayTimeout)
                self.setUpdatesEnabled(False)
    
            super(DelayedUpdater, self).resizeEvent(event)
    
        def _delayedUpdate(self):
            print "Performing actual update"
            self._resizeTimer.stop()
            self.setUpdatesEnabled(True)
    
    
    if __name__ == "__main__":
        app = QtGui.QApplication(sys.argv)
        win = QtGui.QMainWindow()
        view = DelayedUpdater()
        win.setCentralWidget(view)
        win.show()
        view.delayEnabled = True
        app.exec_()
    

    You will notice that as you resize the main window quickly, no updates are occurring for the custom widget, because we have turned them off in the resize event. A QTimer is trying to fire every 100 ms to perform the update and stop itself. But each time another resize event occurs, it will restart that timer. The effect is that timer will continue to be reset. leaving updates disabled, until a delay occurs.

    Try holding down the mouse, resizing a little, wait, and resize some more. The update should occur even while your mouse is down but you are not resizing. Adjust the delay to suit. And you have control over turning the feature on and off with the bool flag.

    This example could also be re-worked to make DelayedUpdater just a QObject, which accepts some QWidget instance as an argument. It would then set itself to be the eventFilter for that object and monitor its resizeEvent. That way you don’t have to subclass normal widgets just to add this. You would simply make an instance of DelayedUpdater and use it as a utility object to monitor the widget.

    Here is an example of making it a helper object:

    class MainWindow(QtGui.QMainWindow):
    
        def __init__(self, parent=None):
            super(MainWindow, self).__init__(parent)
            self.someWidget = QtGui.QWidget()
            self.setCentralWidget(self.someWidget)
    
            self.layout = QtGui.QVBoxLayout(self.someWidget)
            self.label = QtGui.QLabel("Some Text")
            self.layout.addWidget(self.label, QtCore.Qt.AlignCenter)
    
            self.delayer = DelayedUpdater(self.someWidget)
    
    
    class DelayedUpdater(QtCore.QObject):
    
        def __init__(self, target, parent=None):
            super(DelayedUpdater, self).__init__(parent)
            self.target = target
            target.installEventFilter(self)
    
            self.delayEnabled = True
            self.delayTimeout = 100
    
            self._resizeTimer = QtCore.QTimer()
            self._resizeTimer.timeout.connect(self._delayedUpdate)
    
        def eventFilter(self, obj, event):
            if self.delayEnabled and obj is self.target:
                if event.type() == event.Resize:
                    self._resizeTimer.start(self.delayTimeout)
                    self.target.setUpdatesEnabled(False)
    
            return False
    
        def _delayedUpdate(self):
            print "Performing actual update"
            self._resizeTimer.stop()
            self.target.setUpdatesEnabled(True)
    

    Note that we are using this on just some arbitrary widget inside of our main window. We add a delay updater to it with this line:

    self.delayer = DelayedUpdater(self.someWidget)
    

    The DelayedUpdater watches the resize events of the target widget, and performs delayed updates. You could expand the eventFilter to also watch for other events, like a move.

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

Sidebar

Related Questions

I have a Python program uses Qt (PyQt4 in fact) and when I launch
I have the following outline of a Python program (using PyQt4): class Polygon( QtGui.QGraphicsItem
I have a Qt program with many buttons, user-interactable widgets, etc. At one stage
I have a PyQt4 program that I froze using cx_freeze. The problem I am
In a PyQT4 program, I have a QLabel displaying an image with the following
I'm learning to program with PyQT4 and Python. I'm trying to code a simple
So I have been trying to write a GUI using Python 3.3 and PyQt4.
Have a painfully simple blog Post creator, and I'm trying to check if the
I have made a program that has a Toolbar with a few actions on
I have quite a 'heavy' python program that I would like compiled to an

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.