PyQT - 从其他功能修改主窗口小部件
PyQT 初学者问题。我想知道如何执行以下操作 - 从主窗口类外部修改主窗口中的小部件。就像这样:
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MainWindow,self).__init__(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.progressBar.setMaximum(100)
self.ui.progressBar.setMinimum(0)
self.ui.progressBar.setValue(0)
self.connect(self.ui.pushButton, QtCore.SIGNAL('clicked()'), self.slotDoStuff)
def slotDoStuff(self):
AnotherFunction()
def AnotherFunction():
modify progress bar here...
有没有办法做这样的事情?我想对各种主窗口操作的事件处理程序进行子类化,而不是将它们全部放在 MainWindow 类中。谢谢!
A PyQT beginner question. I'm wondering how to do something like the following - modify widgets in the main window from outside the main window class. Like so:
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MainWindow,self).__init__(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.progressBar.setMaximum(100)
self.ui.progressBar.setMinimum(0)
self.ui.progressBar.setValue(0)
self.connect(self.ui.pushButton, QtCore.SIGNAL('clicked()'), self.slotDoStuff)
def slotDoStuff(self):
AnotherFunction()
def AnotherFunction():
modify progress bar here...
Is there a way to do something like this? I'd like to subclass the event handlers for various main window actions and not have them all in the MainWindow class. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,有一种更好的方法将信号连接到 PyQt 上的槽:
您可以使用 lambda 函数将额外的参数传递给方法。
然后你调用
你可以传递任何你想要的东西,包括要修改的MainWindow实例
First, there's a much better way to connect signals to slots on PyQt:
You can use lambda functions to pass extra arguments to methods.
Then you call
You can pass whatever you want, including your MainWindow instance to be modified