尝试抓住要触发动作的对象发出的信号。这是一个最小的示例(每当 QLineEdit 中的文本更改时更新状态栏)。我希望它能满足你的需要。
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.statusBar = QStatusBar()
self.setStatusBar(self.statusBar)
self.statusBar.showMessage('...')
self.lineEdit = QLineEdit()
self.setCentralWidget(self.lineEdit)
self.lineEdit.textEdited.connect(self.updateStatusBar)
def updateStatusBar(self, string):
self.statusBar.showMessage(string)
if __name__ == '__main__':
app = QApplication(sys.argv)
main_window = MainWindow()
main_window.show()
sys.exit(app.exec_())
有关为每个类预定义哪些信号的信息,请参阅文档,例如http://qt-project.org/doc/qt-5.0/qtwidgets/qlineedit.html#signals。