从 GUI 类 PyQt4 以外的类更改进度条的值

发布于 2024-11-16 13:52:30 字数 817 浏览 3 评论 0原文

我有一个由 Qt 设计器创建的 GUI 类,其中有一个进度条,还有另一个类,其中完成所有数字运算,在此期间我希望进度条定期更新。我认为我会这样做的方式是在其他班级中做类似的事情:

gui.progressbar.setValue(some%)

但我似乎无法做到这一点。 gui 类的代码类似于:

from PyQt4 import QtCore, QtGui
from Run import RunProgram

class Ui_mainLayout(QtGui.QWidget):
    def setupUi(self, mainLayout):
        mainLayout.setObjectName(_fromUtf8("mainLayout"))
        def setLayout():
            self.basic_tab = QtGui.QWidget()
            self.progressBar = QtGui.QProgressBar(self.basic_tab)
        setLayout()
        RunProgram()

我当时希望能够做类似的事情:

import gui

class RunProgram:
    def __init__(self):
        something = someMaths
        gui.Ui_mainLayout.progressBar.setValue(something)

但显然,因为我没用,所以这是行不通的,有人能指出我正确的方向吗?请并谢谢你

I have a GUI class created by Qt designer in which i have a progress bar, and another class in which all the number crunching is done during which i want my progress bar to update regularly. The way i thought i would do this it to do something like this in the other class:

gui.progressbar.setValue(some%)

but i cant seem to make that work. the code for the gui class is something like:

from PyQt4 import QtCore, QtGui
from Run import RunProgram

class Ui_mainLayout(QtGui.QWidget):
    def setupUi(self, mainLayout):
        mainLayout.setObjectName(_fromUtf8("mainLayout"))
        def setLayout():
            self.basic_tab = QtGui.QWidget()
            self.progressBar = QtGui.QProgressBar(self.basic_tab)
        setLayout()
        RunProgram()

i was then hoping to be able to do something like:

import gui

class RunProgram:
    def __init__(self):
        something = someMaths
        gui.Ui_mainLayout.progressBar.setValue(something)

but obviously as i am useless this doesnt work, could someone point me in the right direction? please and thank you

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

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

发布评论

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

评论(1

屌丝范 2024-11-23 13:52:30

gui.Ui_mainLayout 不是一个实例化的类,而是一个“类型”对象(可以实例化的对象 - 请参阅 此处 提供良好的概述)。 gui.Ui_mainLayout.progressBar 不会像 setupUi 运行时创建的那样存在。

尝试将 progressBar 显式传递给 RunProgram

from PyQt4 import QtCore, QtGui
from Run import RunProgram

class Ui_mainLayout(QtGui.QWidget):
    def setupUi(self, mainLayout):
        mainLayout.setObjectName(_fromUtf8("mainLayout"))
        def setLayout():
            self.basic_tab = QtGui.QWidget()
            self.progressBar = QtGui.QProgressBar(self.basic_tab)
        setLayout(self.progressBar)
        RunProgram()

class RunProgram:
    def __init__(self, progressBar):
        something = someMaths
        progressBar.setValue(something)

认为会起作用,但我建议将来发布一个您期望的最小示例< /em> 运行可以形成解释的基础。

gui.Ui_mainLayout is not an instantiated class but a 'type' object (an object that can be instantiated - see here for a good overview). gui.Ui_mainLayout.progressBar is not going to exist as its created when setupUi is run.

Try passing progressBar to RunProgram explicitly:

from PyQt4 import QtCore, QtGui
from Run import RunProgram

class Ui_mainLayout(QtGui.QWidget):
    def setupUi(self, mainLayout):
        mainLayout.setObjectName(_fromUtf8("mainLayout"))
        def setLayout():
            self.basic_tab = QtGui.QWidget()
            self.progressBar = QtGui.QProgressBar(self.basic_tab)
        setLayout(self.progressBar)
        RunProgram()

and

class RunProgram:
    def __init__(self, progressBar):
        something = someMaths
        progressBar.setValue(something)

I think that will work, but I suggest in future posting a minimal example you expect to run that can form the basis of the explanation.

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