[PyQt] QPainter::end: Painter ended with 2 saved states
eric.frederich at gmail.com
Tue Jun 28 20:42:51 BST 2011
Here is a reworked example.
Do you see any potential problems with this one?
Is the call to setText okay?
Is it okay to access the data member the way I'm doing it in print_data?
from PyQt4.QtCore import *
from PyQt4.QtGui import *
def __init__(self, parent=None):
self.data = 
for i in xrange(10):
txt = '%02d' % i
from functools import partial
def __init__(self, *args, **kwargs):
super(MyDialog, self).__init__(*args, **kwargs)
self.setWindowTitle("Hey, hows it going?")
layout = QVBoxLayout()
for i in xrange(15):
button = QPushButton("Push Me", self)
self.connect(button, SIGNAL("pressed()"), self.do_something)
b = Blah(self)
partial(self.sender().setText, "Push Me"))
self.connect(b, SIGNAL('ALLDONE'), partial(self.print_data, b))
self.connect(b, SIGNAL('SLEPT'), self.sender().setText)
def print_data(self, blah):
if __name__ == '__main__':
app = QApplication(sys.argv[1:])
md = MyDialog()
On Tue, Jun 28, 2011 at 3:05 PM, Hans-Peter Jansen <hpj at urpla.net> wrote:
> On Tuesday 28 June 2011, 20:52:12 Eric Frederich wrote:
>> I was trying to get an example working with a QThread.
>> I wound up creating one but after running it for a while and pressing
>> buttons I got the error...
>> QPainter::end: Painter ended with 2 saved states
>> Am I doing something wrong?
>> I wanted an example where a worker thread would query a database or
>> some other long running operation and leave the GUI responsive
>> (although disabling certain elements like the button it was launched
>> This is the code I was running....
>> from PyQt4.QtCore import *
>> from PyQt4.QtGui import *
>> class Blah(QThread):
>> def __init__(self, parent=None):
>> super(Blah, self).__init__(parent)
>> print 'new thread created'
>> def run(self):
>> print 'running'
>> import time
>> for i in xrange(10):
>> self.parent().setText("%02d" % i)
>> self.parent().setText("Push Me")
> You're doing "bad" things here, that you shouldn't do from a thread,
> e.g. using methods, that trigger redraws. You should create signals in
> your thread, that signals operations to the main thread, where you
> would actually process these operations without fear.
> PyQt mailing list PyQt at riverbankcomputing.com
More information about the PyQt