Using Python 3.1 and PyQt, I am trying to get a QProgressBar to show that a task is working by having the bars slide across the widget. I found that can be done by setting the minimum and maximum values to 0.
I got it to work properly, but then when integrating it into my program, the bars will only show up in the first 25% of the widget and then reset back to the beginning. I played around for many hours and I think I've narrowed it down to a docstring. Code at the bottom.
If I run the code for the first time, the progress bar works properly. However, any time after that it does not work. If I delete the .pyc file then it works again for the first time only.
When I delete the last character, "j", on the second line of the docstring for def testfunction, or delete the entire docstring, then it always works. Every time.
Is there anything stupid that I'm missing? I don't want to have to change my docstring just to be able to run code properly.
main.py
import sys
from PyQt4 import QtGui
from mainUI import Ui_Form
import comment
class mainForm(QtGui.QDialog):
def __init__( self, parent=None ):
QtGui.QWidget.__init__( self, parent )
self.ui = Ui_Form()
self.ui.setupUi( self )
if __name__ == "__main__":
app = QtGui.QApplication( sys.argv )
myapp = mainForm()
myapp.show()
sys.exit( app.exec_() )
mainUI.py
class comment():
def testfunction( self ):
"""
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghij
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijabcdefghij
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopq
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcde
abcdefghijklmnopqrstuvwxyzabcdefghij
"""
pass
from PyQt4 import QtCore, QtGui
_fromUtf8 = lambda s: s
class Ui_Form(object):
def setupUi(self, Form):
Form.resize(206, 100)
self.pgbTotalProgress = QtGui.QProgressBar(Form)
self.pgbTotalProgress.setGeometry(QtCore.QRect(20, 30, 191, 23))
self.pgbTotalProgress.setMaximum(0)
self.pgbTotalProgress.setProperty(_fromUtf开发者_StackOverflow中文版8("value"), 0)
self.pgbTotalProgress.setObjectName(_fromUtf8("pgbTotalProgress"))
I've seen the same thing happen and managed to fix it by resizing the window slightly.
It sounds crazy, but it worked for me. I'd be interested to know if it makes things work for you too. I noticed the bar work as expected during runtime once the window had been resized and after a couple of minutes of trial and error of setting the initial size of the window it all worked as expected and I've not seen the problem since. I'm thinking maybe a bug in Qt?
精彩评论