从 GUI 类 PyQt4 以外的类更改进度条的值
我有一个由 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
gui.Ui_mainLayout
不是一个实例化的类,而是一个“类型”对象(可以实例化的对象 - 请参阅 此处 提供良好的概述)。gui.Ui_mainLayout.progressBar
不会像setupUi
运行时创建的那样存在。尝试将
progressBar
显式传递给RunProgram
:我
认为会起作用,但我建议将来发布一个您期望的最小示例< /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 whensetupUi
is run.Try passing
progressBar
toRunProgram
explicitly:and
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.