由于 Python 文档字符串注释长度,PyQt QProgressBar 无法正常工作?

发布于 2024-10-21 02:38:41 字数 1729 浏览 0 评论 0原文

使用 Python 3.1 和 PyQt,我试图通过让条在小部件上滑动来获取 QProgressBar 来显示任务正在工作。我发现可以通过将最小值和最大值设置为 0 来完成。

我让它正常工作,但是当将其集成到我的程序中时,条形图只会显示在小部件的前 25% 中,然后重置回来到开始。我玩了很多小时,我想我已经将其范围缩小到了文档字符串。代码在底部。

如果我第一次运行代码,进度条可以正常工作。然而,此后的任何时间它都不起作用。如果我删除 .pyc 文件,那么它只能在第一次再次工作。

当我删除 def testfunction 文档字符串第二行的最后一个字符“j”,或删除整个文档字符串时,它总是有效。每次。

我错过了什么愚蠢的事情吗?我不想仅仅为了能够正确运行代码而更改我的文档字符串。

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(_fromUtf8("value"), 0) self.pgbTotalProgress.setObjectName(_fromUtf8("pgbTotalProgress"))

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(_fromUtf8("value"), 0) self.pgbTotalProgress.setObjectName(_fromUtf8("pgbTotalProgress"))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁拥 2024-10-28 02:38:41

我也见过同样的事情发生,并通过稍微调整窗口大小来解决它。

听起来很疯狂,但它对我有用。我很想知道它是否也适合您。我注意到,一旦窗口大小被调整,栏在运行时就会按预期工作,并且在设置窗口初始大小的几分钟尝试和错误之后,一切都按预期工作,从那以后我就没有看到问题了。我在想 Qt 中可能有一个错误吗?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文